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>
I have also tried the variant
Binding="{Binding Path=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));
}
}
));
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…