wpf - 如何通过 generic.xaml 中定义的键访问资源

标签 wpf xaml resourcedictionary

当前我正在使用 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/

相关文章:

c# - 将对话框置于窗口之上,但不置于所有内容之上

c# - 创建包含 ResourceDictionary 的 DLL

.net - 从父控件设置 WPF 嵌套控件属性

wpf - 合并字典和本地资源

wpf - 在 ResourceDictionary 内的共享 WPF 资源中启用数据绑定(bind)

c# - WPF 效果在哪里定义?

C# 检查文本文件是否有内容

wpf - 在 UserControl 中引用父级的 ResourceDictionary

c# - 如何在 Visual Studio Express 2012 中添加 resx 文件?

c# - 如何通过 ListView 中的文本框进行 TAB