I have a TextBox Style with a Key defined in external resource dictionary file, then I'm trying to define a new implicit TextBox Style that sets "Keyed" style from resource dictionary, so basically I want to seet the style from resource dictionary as a default for TextBox, but I c开发者_StackOverflowan't remove Key from there, because it is used by other code.
<ResourceDictionary Source="FileWithNiceTextBoxStyle.xaml"/>
<Style TargetType="TextBox">
<Setter Property="Style" Value="{StaticResource NiceTextBoxStyle}"/>
</Style>
However this doesn't work, and result in Visual Studio crash.
Use the BasedOn
attribute:
<Style TargetType="TextBox" x:Key="GlobalTextBox">
<Setter Property="Background" Value="Pink"/>
</Style>
<Style TargetType="TextBox" BasedOn="{StaticResource GlobalTextBox}"></Style>
...
<TextBox Text="I have pink background"/>
精彩评论