C# WPF包含资源目录XamlParserException
我有这样一个用户控件:C# WPF包含资源目录XamlParserException,c#,.net,wpf,xaml,exception,C#,.net,Wpf,Xaml,Exception,我有这样一个用户控件: <UserControl x:Class="LoginModule.LoginView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:controls="clr-namespace:UserControls;assembly=UserControls" xmlns:x="http://schemas.microsoft.com/winfx/20
<UserControl x:Class="LoginModule.LoginView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:controls="clr-namespace:UserControls;assembly=UserControls"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<UserControl.Resources>
<ResourceDictionary Source="pack://application:,,,/UserControls;component/Styles.xaml" />
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="30" />
<RowDefinition Height="30" />
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<Label Grid.Row="1" Grid.Column="0" Name="labelLogin" VerticalAlignment="Center">Login:</Label>
<Label Grid.Row="2" Grid.Column="0" Name="labelPassword" VerticalAlignment="Center">Password:</Label>
<TextBox Grid.Row="1" Grid.Column="1" Name="textboxLogin" VerticalAlignment="Center"></TextBox>
<TextBox Grid.Row="2" Grid.Column="1" Name="textboxPassword" VerticalAlignment="Center"></TextBox>
<Button Grid.Row="3" Grid.ColumnSpan="2" Template="{StaticResource SilverButton}" Height="25" Width="200" Name="buttonLogin" Content="Log In" Click="buttonLogin_Click" />
</Grid>
</UserControl>
登录:
密码:
在designer模式下,一切正常(风格正常),所有解决方案都成功构建。但是,当我使用debug运行程序时,会在以下位置出现XamlParserException:
<ResourceDictionary Source="pack://application:,,,/UserControls;component/Styles.xaml" />
消息如下:无法将UserControl加载到他的一个元素。无法加载文件。
我引用了UserControl.dll,我不知道发生了什么
谢谢你的快速帮助。
Kamilos我认为这是因为您需要使用合并词典:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/YourAssembly;component/YourResource.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
我认为这是因为您需要使用合并词典:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/YourAssembly;component/YourResource.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
您的用户控件是否使用任何XML文件进行解析…如果可能,请粘贴您的用户控件代码如果可能,请粘贴您的用户控件是否使用任何XML文件进行解析…如果可能,请粘贴您的用户控件代码