I have an issue with using Styles on DataTemplates in WPF … It appears to suck. Suppose that you define a DataTemplate:
<DataTemplate DataType="{x:Type local:DataSource}">
<TextBox Style="{StaticResource TextBoxStyle}" Text="{Binding Path=myData}" />
</DataTemplate>
Is there now any way to dynamically style this element? (eg. change the background color in some parts of the application) My problems are:
- if you set a style in some parent-control, it gets ignored since there is already a style in the datatemplate
- if you set a property on a parent-control, it doesn’t get inherited since styles have precedence over property inheritence
Does anyone see a way to do this?
you can try it using DynamicResource
and then later if you need to change the style in any other control. you can just declare same resource with same key for that control. Suppose you are using it in ListBox.
new style will apply over there.