【发布时间】:2013-03-14 09:55:29
【问题描述】:
当前我正在使用Generic.xaml 并在其中定义了一个自定义类实例。如下:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/TextPicker;component/Themes/FiltersTreeView.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
在FiltersTreeView.xaml 中,我定义了一个自定义 UI 类的实例。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:utils="clr-namespace:TextPicker.Utils"
xmlns:cmd="clr-namespace:TextPicker.Commands"
xmlns:cc="clr-namespace:TextPicker.CustomControls"
xmlns:dm="clr-namespace:TextPicker.Models">
<cc:ColorPiePopup x:Key="colorPiePopup"/>
....
<ResourceDictionary/>
现在,我尝试使用Application.Current.FindResource 来查找它,但它总是返回null。
那么我怎样才能从Generic.xaml 中定义这个资源呢?我的意思是使用代码。
【问题讨论】:
-
您是否在 App.xaml 中将 Generic.xaml 添加为
ResourceDictionary? -
AssemblyInfo.as 中有 ThemeInfo::ResourceDictionaryLocation.SourceAssembly,够吗?我检查了 App.xaml,目前 Generic.xaml 不在其中,但 Generic.xaml 确实有效,因为其中的其他样式设置适用于我的控件。
标签: wpf xaml resourcedictionary