locked
ResourceDictionary.MergedDictionaries System.Windows.Markup.XamlParseException RRS feed

  • Question

  • I have the following configuration. I got a dll called hdn.Styles. containing a file called hdn.WizStyles.xaml with this content.

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:inpctls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input">
         <Style x:Key="WizRootLayout" TargetType="Grid">
        </Style>

         <Style x:Key="WizPgRootLayout" TargetType="Grid">
        </Style>

         <Style x:Key="WizTitle" TargetType="inpctls:Label">
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="Margin" Value="3" />
        </Style>

         <Style x:Key="WizText" TargetType="inpctls:Label">
            <Setter Property="FontSize" Value="11"/>
            <Setter Property="Margin" Value="3" />
        </Style>

       <Style x:Key="WizCtlLabel" TargetType="inpctls:Label">
            <Setter Property="FontSize" Value="11"/>
            <Setter Property="FontWeight" Value="Bold"/>
            <Setter Property="Margin" Value="3" />
        </Style>

    </ResourceDictionary>

    In my wizard control project I reference the hdn.Styles.dll and in the controls asmx I inserted this section to include the resource.

    <UserControl.Resources>
      <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
          <ResourceDictionary Source="/hdn.Styles;component/hdn.WizStyles.xaml" />
        </ResourceDictionary.MergedDictionaries>
      </ResourceDictionary>
    </UserControl.Resources>

    Now in design mode everything works fine. I see the styles getting applied. But if I call the wizard control from my Silverlight application I get the following error.

    System.Windows.Markup.XamlParseException occurred

      Message=Failed to assign to property 'System.Windows.ResourceDictionary.Source'. [Line: 13 Position: 44]
      LineNumber=13
      LinePosition=44
      StackTrace:
           at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
      InnerException: System.Collections.Generic.KeyNotFoundException
           Message=The given key was not present in the dictionary.
           StackTrace:
                at System.ThrowHelper.ThrowKeyNotFoundException()
                at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
                at System.Windows.ResourceManagerWrapper.GetResourceForUri(Uri xamlUri, Type componentType)
           InnerException:

    If I add a file e.g. hdn.LocalWizStyles.xaml into my wizard control project and define the reference like this

    <ResourceDictionary>
         <ResourceDictionary.MergedDictionaries>
              <ResourceDictionary Source="hdn.LocalWizStyles.xaml"/>
         </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

     Everythings works well.

    Any idea how to find out what causes the System.Windows.Markup.XamlParseException?

    Wednesday, August 18, 2010 10:39 AM

Answers

  • Hi Frank

    Thanks for the sample. It works! As my project implements a Silverlight app which just serves as a test container for a user control which then opens a window which finally embeds the wizard control, I added a user control to your project and copied the code of the MainPage.xaml into that control. I also added a reference to the hdn.Styles assembly at the controls project. Then I placed the control into the main page and it still worked. Now I uncommented the content of the main page except the control and removed the reference to the hdn.Styles assembly. And, not really surprising, the problem occurred. So I realized it must have to do with the hdn.Styles assembly reference. I opened my project and added a reference to the hdn.Styles assembly at the app using the control through another control. This solved to problem. Before, I checked the content of the xab file and recognized that the hdn.Styles.dll is missing, even though Copy Local was set to true in the assembly reference of the control. The whole behavior is a bit strange to me. I think the Silverlight app hosting a control, which may use several other controls itself, should be aware of all referenced assemblies and include them automatically. Anyway the problem is solved. Thanks a lot for your support.

     

    Wednesday, August 25, 2010 3:15 AM

All replies

  • Hi,

    Please check the build action of your hdn.Styles.xaml to make sure it's Resources or Page. If that doesn't help, please let me know, I will upload a complete working sample according to your scenario.  Thanks.

    Thursday, August 19, 2010 10:43 PM
  • Hi Frank 

    I did already, I'm back at page but I tried Resource too. And by the way it worked once. I also created a sample called theme switcher which I got from http://johnlivingstontech.blogspot.com/2010/05/dynamic-silverlight-theme-switcher.html it worked once and now it throws this exeption.

    System.Windows.Markup.XamlParseException occurred
      Message=Invalid attribute value input:AutoCompleteBox for property TargetType. [Line: 1 Position: 214]

    when I try to create a theme. e.g.

    Theme t = new ExpressionLightTheme() { Content = c };

    Content is derived from UserControl

    public partial class Content : UserControl
    Content c = new Content();

    Any way, it would be great if you could supply me with a working sample.

     

    Friday, August 20, 2010 2:20 AM
  • Hi,

    Sorry for the late, here is a working sample, please give it a try:

    http://cid-1bf46693be07cfa6.office.live.com/self.aspx/.Public/Forum196900.zip 

    Tuesday, August 24, 2010 1:15 AM
  • Hi Frank

    Thanks for the sample. It works! As my project implements a Silverlight app which just serves as a test container for a user control which then opens a window which finally embeds the wizard control, I added a user control to your project and copied the code of the MainPage.xaml into that control. I also added a reference to the hdn.Styles assembly at the controls project. Then I placed the control into the main page and it still worked. Now I uncommented the content of the main page except the control and removed the reference to the hdn.Styles assembly. And, not really surprising, the problem occurred. So I realized it must have to do with the hdn.Styles assembly reference. I opened my project and added a reference to the hdn.Styles assembly at the app using the control through another control. This solved to problem. Before, I checked the content of the xab file and recognized that the hdn.Styles.dll is missing, even though Copy Local was set to true in the assembly reference of the control. The whole behavior is a bit strange to me. I think the Silverlight app hosting a control, which may use several other controls itself, should be aware of all referenced assemblies and include them automatically. Anyway the problem is solved. Thanks a lot for your support.

     

    Wednesday, August 25, 2010 3:15 AM