2010-07-02 39 views
1

我有一個用戶控件這樣的:WPF包括資源目錄XamlParserException

<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> 

在設計模式一切正常(風格的作品),所有解決方案構建成功。但是,當我運行程序的調試,我得到XamlParserException在:

<ResourceDictionary Source="pack://application:,,,/UserControls;component/Styles.xaml" /> 

與像消息:無法加載用戶控件OIR他的元素之一。無法加載文件。 我有參考UserControl.dll我不知道發生了什麼事。

感謝您的快速幫助。 Kamilos

+0

使用是用於解析任何XML文件的用戶控件....貼上您的用戶控件的代碼,如果可能的 – 2011-01-21 23:05:28

回答

1

我想這是因爲你需要使用合併字典:

<UserControl.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="pack://application:,,,/YourAssembly;component/YourResource.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</UserControl.Resources> 
+0

沒了,得到了相同的 – Kamilos 2010-07-02 14:21:50

+0

你可以添加確切的錯誤信息,你得到您的文章? – 2010-07-02 14:26:53