XAML 如何在另一个项目WPF中引用字典

8fq7wneg  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(134)

[自定义控件Wpf库]

Test
-->Resources
    -->Resources
       -->Dictionary1.xaml (Reusable across multiple project)
       -->Dictionary2.xaml(Reusable across multiple project)

[WPF主UI]测试研发

-->Resources
    -->Resources
       -->Dictionary9.xaml(Specific to the project)

XAML:字典1.xml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <SolidColorBrush x:Key="brush" Color="Red"/>
</ResourceDictionary>

Dictionary2.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <SolidColorBrush x:Key="brush" Color="Green"/>
</ResourceDictionary>

Dictionary9.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <!--How can I use the resource from another DLL here-->
</ResourceDictionary>

1.如何在Dictionary9中引用Dictionary1或Dictionary2?
1.这是否可取,尤其是在模块化项目中?
我有一些样式,我想全局移动,这样我就可以重复使用,并停止复制和粘贴他们。

toiithl6

toiithl61#

1.如何在Dictionary9中引用Dictionary1或Dictionary2?
试试这个:

    • 字典9.xaml**
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <!--How can I use the resource from another DLL here-->
    <ResourceDictionary Source="pack://application:,,,/Resources;component/Resources/Dictionary1.xaml" />
    <ResourceDictionary Source="pack://application:,,,/Resources;component/Resources/Dictionary2.xaml" />
</ResourceDictionary>

请注意,第一个"资源"是您的库名称,第二个"资源"是您的库中的文件夹名称。您可以在here中找到更多信息。
1.这是否可取,尤其是在模块化项目中?
如果你重复使用或需要分开这些字典,IMO是完全可以的。

相关问题