I have a style for a WPF text box which looks some thing like this. The template has a button on whose button clicked event i need the text to be set to empty. Can someone tell what am i missing. Or how can I call a method inside the custom SearchTextBox say ( OnButtonClikced) custom method
<Style TargetType="{x:Type DevExGrdDemo:SearchTextBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DevExGrdDemo:SearchTextBox}">
<Border x:Name="Border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid x:Name="LayoutGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ActualHeight}" />
</Grid.ColumnDefinitions>
<ScrollViewer x:Name="PART_ContentHost"
Grid.Column="0"
Margin="2" />
<Label x:Name="LabelText"
Grid.Column="0"
Margin="2"
Content="Search"
FontStyle="Italic"
Padding="2,0,0,0" />
<Button x:Name="SearchBoxButton"
Grid.Column="1"
Style="{DynamicResource SearchButton}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click" >
<"A method residing in the SearchTextBox called on button click">
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="HasText" Value="True">
<Setter TargetName="LabelText" Property="Visibility" Value="Hidden" />
<Setter TargetName="SearchBoxButton" Property="Style" Value="{StaticResource CancelSearchButton}" />
</Trigger>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter TargetName="LabelText" Property="Visibility" Value="Hidden" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
use an event trigger on the style (not on the ControlTemplate)
http://msdn.microsoft.com/en-us/library/system.windows.eventtrigger.aspx
You can’t put setters in an EventTrigger 🙁
However, you can use a storyboard 🙂