当前我正在使用 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
中获得定义的这个资源? ?我的意思是使用代码。
最佳答案
这个问题有答案here :
You can not access the resource in generic.xaml in your app directly. [...] So if you want to use the resource in the generic.xaml, you should add it as a general ResourceDictionary in your app
关于wpf - 如何通过 generic.xaml 中定义的键访问资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15405990/