How to use a style several times in a resourcedictionary from an external resourcedictionary?

余生长醉 提交于 2019-12-12 05:36:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!