问题
I have a style for button inside a resourcedictionary, and now I want to use this style in another resource several times(for several buttons), but it just effects on the last button. What's the problem here?
Edit: this is my style:(CommonControlStyles.xaml)
<ResourceDictionary .....>
.
.
.
<Style TargetType="{x:Type Button}" x:Key="ListButtonsStyle">
<Setter Property="MaxHeight" Value="35"/>
<Setter Property="Width" Value="20"/>
<Setter Property="Content">
<Setter.Value>
<Image Source="Images\up.png"/>
</Setter.Value>
</Setter>
</Style>
.
.
.
</ResourceDictionary>
and now i want to use this style in another resource dictionary(myResourcedictionary.Xaml)
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/...StyleResource;component/CommonControlStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
<Button x:Name="btn1" Grid.Column="0" Style="{DynamicResource ListButtonsStyle}"/>
<Button x:Name="btn2" Grid.Column="0" Style="{DynamicResource ListButtonsStyle}"/>
<Button x:Name="btn3" Grid.Column="0" Style="{DynamicResource ListButtonsStyle}"/>
but it just effects on btn3!!
回答1:
It isn't DynamicResource
it should be StaticResource
.
You should use DynamicResource
for changeable resources (for example: system colors). But your style is constant and StaticResource
should be your choice.
来源:https://stackoverflow.com/questions/10258207/how-to-use-a-style-several-times-in-a-resourcedictionary-from-an-external-resour