将外部xaml样式从库引用到WPF主应用程序
我在VB.NET上有一个主App.exe WPF。应用程序有一个库C#.NET。 应用程序参考项目库 我试图从外部库获取样式,但给出了错误 这是我的“Sharp.LIB”项目:“Dictionaries/Buttons.xaml”将外部xaml样式从库引用到WPF主应用程序,wpf,resources,Wpf,Resources,我在VB.NET上有一个主App.exe WPF。应用程序有一个库C#.NET。 应用程序参考项目库 我试图从外部库获取样式,但给出了错误 这是我的“Sharp.LIB”项目:“Dictionaries/Buttons.xaml” 这是我的第二个文件“General.xaml”,用于标记所有样式。现在我只合并一个按钮样式 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml
这是我的第二个文件“General.xaml”,用于标记所有样式。现在我只合并一个按钮样式
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionaries/Buttons.xaml" />
</ResourceDictionary.MergedDictionaries>
这是我在主vb.net应用程序中的usercontrol
<UserControl x:Class="MyWF.UC"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ms="clr-namespace:MyStyles;assembly=MyStyles" mc:Ignorable="d"
d:DesignHeight="100" d:DesignWidth="100">
<UserControl.Resources>
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MyStyles;component/General.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Button Style="{StaticResource MyButton}" />
</Grid>
这是我第二次尝试。根据丢失的文件,再次失败,并出现相同错误
<UserControl x:Class="MyWF.UC"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ms="clr-namespace:MyStyles;assembly=MyStyles" mc:Ignorable="d"
d:DesignHeight="100" d:DesignWidth="100">
<UserControl.Resources>
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MyStyles;component/General.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Button Style="{StaticResource MyButton}" />
</Grid>
错误:
其他信息:“Set property”System.Windows.ResourceDictionary.Source“引发了异常。行号“27”和行位置“18”
{“找不到资源'general.xaml'。”
请帮助。您是否尝试过完全限定的包URI?请查看以下网页上的“资源文件包URI”部分:是的,但问题仍然存在。您是否尝试过完全限定的包URI?查看以下网页上的“资源文件包URI”部分:是的,但问题仍然存在。
<UserControl x:Class="MyWF.UC"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ms="clr-namespace:MyStyles;assembly=MyStyles" mc:Ignorable="d"
d:DesignHeight="100" d:DesignWidth="100">
<UserControl.Resources>
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MyStyles;component/General.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Button Style="{StaticResource MyButton}" />
</Grid>