1

例如,我有风格

<Style TargetType="Button">
...
</Style>

在文件 Button.xaml 如果我使用 MergeDictionary 在我想使用它的文件中添加这种样式 - 一切都很好。但是,如果我在文件层次结构中将这种样式连接得更高(例如在 App.xaml 中)样式停止工作,直到我为它和所有按钮集设置 x:Key

样式=“{StaticResource name_of_style}”。

我可以避免这种行为还是必须按名称为我的所有元素样式设置?

4

1 回答 1

2

尝试将其设置为 app.xaml 中的应用程序资源,如果您对视图的 UserControl.Resources 执行相同操作,则在调用特定样式到特定视图时也可以执行相同操作。

PS - 示例是 silverlight,但方法保持不变。

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
              x:Class="The.App">
    <Application.Resources>
        <Style TargetType="Button" BasedOn="{StaticResource name_of_style}"/>
    </Application.Resources>
于 2012-02-14T14:46:07.213 回答