以下に示すように、ビューモデル プロパティからバインディング値を取得する単純なスタイル データ トリガーを作成しようとしています。
<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));
}
}
));
}