WPF中如何在xaml文件里使用合并字典资源中的样式
WPF中怎么在xaml文件里使用合并字典资源中的样式?
AppDictionary.xaml文件中就设置了一个Button的样式,Key为CommonBtnStyle;
在合并的xaml文件中怎么去访问CommonBtnStyle
<Button Style="AppStyle"/>
这样好像不行啊。。。。。
------解决方案--------------------
那是uri路径、或者是指定了 x:Key 的问题, 你用鼠标右键看看 AppDictionary.xaml 属性,其中“生成操作”是不是“Page”(这是默认值)
如果是 Page ,则在 App.xaml 中为
- XML code
<ResourceDictionary x:Key="AppStyle"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary x:Name="nn" Source="../Styles/AppDictionary.xaml"></ResourceDictionary> </ResourceDictionary.MergedDictionaries> </ResourceDictionary>
AppDictionary.xaml文件中就设置了一个Button的样式,Key为CommonBtnStyle;
- XML code
<!--定义按钮样式--> <Style TargetType="Button" x:Key="CommonBtnStyle"> <Setter Property="Foreground" Value="Black"/> .......
在合并的xaml文件中怎么去访问CommonBtnStyle
<Button Style="AppStyle"/>
这样好像不行啊。。。。。
------解决方案--------------------
那是uri路径、或者是指定了 x:Key 的问题, 你用鼠标右键看看 AppDictionary.xaml 属性,其中“生成操作”是不是“Page”(这是默认值)
如果是 Page ,则在 App.xaml 中为
- XML code
<Application x:Class="WpfApplication12.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> <Application.Resources> <ResourceDictionary > <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/Styles/AppDictionary.xaml"></ResourceDictionary> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application>