I would like to set Triggers for the controls in a DataTemplate. Whenever I set a property of the control within the DataTemplate, it seems not working. However, If do not set the property within the TextBlock inside the DataTemplate, then I can see the effect of Trigger in the style (it works). I am not sure whether using Style Triggers with DataTemplate is good or not! The XAML is below;
<Grid> <Grid.Resources> <Style TargetType="TextBlock" x:Key="BlockOf"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="FontWeight" Value="ExtraBold" /> <Setter Property="FontSize" Value="22" /> </Trigger> </Style.Triggers> </Style> </Grid.Resources> ...........
DataTemplate for the button,
<Button.ContentTemplate> <DataTemplate DataType="Button"> <TextBlock Style="{DynamicResource BlockOf}" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}" FontStyle="Italic" FontSize="9"/> </DataTemplate> </Button.ContentTemplate>