我正在尝试创建一个简单的样式数据触发器,它从 viewmodel 属性中提取它的绑定值,如下所示:
<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属性的按钮时这仍然不起作用我做错了什么?
我已经这样实现了该属性:
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");
}
}
这是实现变更控制的方法
public virtual void OnPropertyChanged(string propertyInfo)
{
App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyInfo));
}
}
));
}