In such cases, I usually prefer the ViewModel / Model to do the βclearβ part of the functionality,
therefore, in your case, I usually do something like:
public bool IsSelected { get { return _isSelected; } private set { if (value == _isSelected) return; RaisePropertyChanging(() => IsSelected); _isSelected = value; RaisePropertyChanged(() => IsSelected); if (_isSelected == false) Amount = string.Empty } }
Thus, the view is not responsible for any logic and therefore does not need a DataTrigger at all
Update:
The problem with your code is that when you install Text with a binding in a TextBox, it takes precedence over the value set in Style for the Text property. You can verify this using the following:
<TextBox> <TextBox.Style> <Style TargetType="{x:Type TextBox}"> <Setter Property="Text" Value="{Binding Path=Amount, Mode=TwoWay}" /> <Style.Triggers> <DataTrigger Binding="{Binding Path=IsSelected}" Value="false"> <Setter Property="Text" Value="{x:Null}" /> </DataTrigger> </Style.Triggers> </Style> </TextBox.Style> </TextBox>
Now the text will be cleared if CheckBox checked, however it will not update the binding ( Amount ), since essentially your binding is only active when you select CheckBox .
source share