从 dll 加载 xaml ResourceDictionary
Load xaml ResourceDictionary from dll
我已经制作了几个 ResourceDictionaries
供我们的应用程序团队用于他们未来的应用程序。我已经将包含这些词典的 class 库项目的内容部署到一个 .dll 文件中,并且希望能够通过在我希望的新 WPF 解决方案中添加对 .dll 文件的引用来使用这些词典重新申请。
我的示例中的 Class 库称为 "NWF_Class_Library.dll" 并保存在 windows 资源管理器中与 MainWindow.xaml
文件相同的文件夹中。是否可以从中检索资源字典?
我已经阅读了有关组织获取 arrange their xaml 资源的最佳方式的文章,因此它似乎是可行的,但我所找到的只是使用“//pack:application:.. ." 在与 wpf 应用程序相同的解决方案中引用 xaml 的语法。这是一段代码,Source 是空白的,因为我写的任何东西都不起作用!
我们本来希望可以将标准配置以及我们更常用的有用方法等添加到一个可以与应用程序一起部署的文件中。
<Window x:Class="dll_ref_included.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<ResourceDictionary Source=""/>
</Window.Resources>
<Grid>
<Button Style="{StaticResource myButton}">This</Button>
</Grid>
</Window>
试试这个:
<ResourceDictionary Source="pack://application:,,,/NWF_Class_Library;component/Dictionary1.xaml"/>
...其中 "NWF_Class_Library" 是引用程序集的名称,"Dictionary1.xaml" 是在此项目中定义的 ResourceDictionary
的名称。
您可以参考 documentation 了解有关包 URI 及其使用方法的更多信息。
我已经制作了几个 ResourceDictionaries
供我们的应用程序团队用于他们未来的应用程序。我已经将包含这些词典的 class 库项目的内容部署到一个 .dll 文件中,并且希望能够通过在我希望的新 WPF 解决方案中添加对 .dll 文件的引用来使用这些词典重新申请。
我的示例中的 Class 库称为 "NWF_Class_Library.dll" 并保存在 windows 资源管理器中与 MainWindow.xaml
文件相同的文件夹中。是否可以从中检索资源字典?
我已经阅读了有关组织获取 arrange their xaml 资源的最佳方式的文章,因此它似乎是可行的,但我所找到的只是使用“//pack:application:.. ." 在与 wpf 应用程序相同的解决方案中引用 xaml 的语法。这是一段代码,Source 是空白的,因为我写的任何东西都不起作用!
我们本来希望可以将标准配置以及我们更常用的有用方法等添加到一个可以与应用程序一起部署的文件中。
<Window x:Class="dll_ref_included.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<ResourceDictionary Source=""/>
</Window.Resources>
<Grid>
<Button Style="{StaticResource myButton}">This</Button>
</Grid>
</Window>
试试这个:
<ResourceDictionary Source="pack://application:,,,/NWF_Class_Library;component/Dictionary1.xaml"/>
...其中 "NWF_Class_Library" 是引用程序集的名称,"Dictionary1.xaml" 是在此项目中定义的 ResourceDictionary
的名称。
您可以参考 documentation 了解有关包 URI 及其使用方法的更多信息。