C# WPF-Tips-プロパティ値変更時のCommand実行
WPFってプロパティ変更時にCommandを仕込みたい時ありますよね。
Setterに書くのはどうも綺麗じゃないので、、、
そんな時は"PropertyChangedTrigger"を使います。
Nugetの設定
Nugetで"Microsoft.Xaml.Behaviors.Wpf"を取得し、
Xamlで読み込みます。
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
PropertyChangedTrigger
<TextBox x:Name="NameA" Text="{Binding Name, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"> <i:Interaction.Triggers> <i:PropertyChangedTrigger Binding="{Binding NameA}"> <i:InvokeCommandAction Command="{Binding StartCommand}"/> </i:PropertyChangedTrigger> </i:Interaction.Triggers> </TextBox>
"NameA"の値を変更したら"StartCommand"を実行します。