如何将多个资源添加到 XAML 窗口? [英] How to add more than one resource to a XAML window?

查看:72
本文介绍了如何将多个资源添加到 XAML 窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有一个小问题,我不知道如何解决.我想向一个窗口添加两个资源.一个是 XAML 文件样式资源,另一个是 ValueConverter 类.

I have a little problem right now and I don't know how to fix it. I want to add two resources to a window. One is a XAML File style resource, the other a ValueConverter Class.

如果我一次只使用一种资源,它们都可以工作:

Both of them work if I use only one resource at a time:

 <Window.Resources>
    <ResourceDictionary Source="Resources\MyStyles.xaml" />
 <Window.Resources>

<Window.Resources>
    <local:MarginConverter x:Key="adjustMargin"/>
</Window.Resources>

但是如果我尝试这样的事情:

But if I try something like this:

<Window.Resources>
    <local:MarginConverter x:Key="adjustMargin"/>
    <ResourceDictionary Source="Resources\MyStyles.xaml" />
</Window.Resources>

我收到消息资源已经设置,不能设置两次.

I get the message the resource is already been set and can not set twice.

我不知道如何完成这项工作.有没有类似资源组的东西?

I have no idea how to get this done. Is there something like a resource group?

推荐答案

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources\MyStyles.xaml" />
        </ResourceDictionary.MergedDictionaries>

        <local:MarginConverter x:Key="adjustMargin"/>
    </ResourceDictionary>
</Window.Resources>

这篇关于如何将多个资源添加到 XAML 窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆