datatrigger绑定到viewmodel属性

编程入门 行业动态 更新时间:2024-10-27 04:31:35
本文介绍了datatrigger绑定到viewmodel属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试创建一个简单的样式数据触发器,该触发器将其绑定值从viewmodel属性中拉出,如下所示:

I'm trying to create a simple style data trigger that pulls it's binding value from a viewmodel property, as you can see below:

<StackPanel Name="stackTextPanel" Orientation="Horizontal" Margin="0,8,0,0"> <StackPanel.Style> <Style TargetType="{x:Type StackPanel}"> <Style.Triggers> <DataTrigger Binding="{Binding QuickDrawBarPinned}" Value="False"> <Setter Property="Margin" Value="0,8,0,0" /> </DataTrigger> <DataTrigger Binding="{Binding QuickDrawBarPinned}" Value="True"> <Setter Property="Margin" Value="0,48,0,0" /> </DataTrigger> </Style.Triggers> </Style> </StackPanel.Style>

我也尝试过变种

Binding="{Binding Path=QuickDrawBarPinned}"

但是当我按下更改 QuickDrawBarPinned 属性的按钮时,这仍然不起作用吗?

but this is still not working when I press the button that changes the QuickDrawBarPinned property what am I doing wrong?

我已经按如下方式实现了该属性:

I've implemented the property as so:

private bool _quickDrawBarPinned = false; /// <summary> /// Indicates if the Quick Draw Bar is pinned (stuck) or unpinned (retractable) /// </summary> public bool QuickDrawBarPinned { get { return _quickDrawBarPinned; } set { _quickDrawBarPinned = value; OnPropertyChanged("QuickDrawBarPinned"); } }

这是实现变更控制的方法

This is the method that implements the change control

public virtual void OnPropertyChanged(string propertyInfo) { App.Current.Dispatcher.BeginInvoke((Action)(() => { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyInfo)); } } )); }

推荐答案

我认为您必须删除本地样式以获取利润

I think you have to remove to local style for your margin

<StackPanel Name="stackTextPanel" Orientation="Horizontal"> <StackPanel.Style> <Style TargetType="{x:Type StackPanel}"> <Setter Property="Margin" Value="0,8,0,0" /> <Style.Triggers> <DataTrigger Binding="{Binding QuickDrawBarPinned}" Value="False"> <Setter Property="Margin" Value="0,8,0,0" /> </DataTrigger> <DataTrigger Binding="{Binding QuickDrawBarPinned}" Value="True"> <Setter Property="Margin" Value="0,48,0,0" /> </DataTrigger> </Style.Triggers> </Style> </StackPanel.Style>

更多推荐

datatrigger绑定到viewmodel属性

本文发布于:2023-11-14 16:31:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1587965.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   属性   datatrigger   viewmodel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!