首页 > 解决方案 > 如何将控件模板添加到资源字典?

问题描述

所以我想创建一个ComboBox的模板副本,但不是在MainWindow中定义它,而是在一个专门创建的资源目录中。

我得到了什么:

<Application x:Class="dingeTesten.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:local="clr-namespace:dingeTesten"
         StartupUri="MainWindow.xaml">
<Application.Resources>
    <ResourceDictionary Source="Dictionary1.xaml"/>
</Application.Resources>

现在我创建了一个名为 Dictionary1.xaml 的 RessourceDictionaray。在这个文件中,我想要我的 ComboBox 的模板副本,但是当我创建一个模板时,我无法选择这个文件: 图片1

它是德语的,但我不能选择最后一个选项 RessourceDictionary 来将此模板保存在我的 RessourceDictionary 中。

标签: wpfxaml

解决方案


我想您正在尝试为ComboBoxin创建一种样式Blend。要启用选项,Resource dictionary您必须添加ResourceDictionaryMergedDictionaries.App.xaml

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Dictionary1.xaml"/>
            <ResourceDictionary Source="Dictionary2.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

然后Resource dictionary选项将被启用。

在此处输入图像描述


推荐阅读