вы можете использовать прикрепленное свойство
public static class TextBoxBehaviour
{
public static bool GetClearAll(TextBox target)
{
return (bool)target.GetValue(ClearAllAttachedProperty);
}
public static void SetClearAll(TextBox target, bool value)
{
target.SetValue(ClearAllAttachedProperty, value);
}
public static readonly DependencyProperty ClearAllAttachedProperty =
DependencyProperty.RegisterAttached("ClearAll", typeof(bool), typeof(TextBoxBehaviour), new UIPropertyMetadata(false, OnClearAllAttachedPropertyChanged));
static void OnClearAllAttachedPropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
((TextBox)o).Clear();
}
}
использование
<ControlTemplate.Triggers>
<Trigger SourceName="SearchBoxButton"
Property="IsPressed"
Value="True">
<Setter Property="WpfStackOverflowSpielWiese:TextBoxBehaviour.ClearAll"
Value="True" />
</Trigger>
</ControlTemplate.Triggers>