none
Error "XamlParseException: Missing key value on 'CompositeCollection' object" in designer RRS feed

  • Frage

  • I've built an ItemsControl that displays various cards containing ListViews. One of those ListViews is displaying data from a CompositeCollection. The CompositeCollection is a combination of items from the base control and sub items from the data that is bound to the ListView.

    This is working perfectly when I compile the application, but I would also like to have a preview of the cards in this control in the designer. So I've added a design data class that provides some example data. But as soon as I enable the design data I get the following error in the designer:

    XamlParseException: Missing key value on 'CompositeCollection' object.

    at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
       at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter)
       at System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
       at System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren)
       at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
       at System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
       at System.Windows.FrameworkElement.ApplyTemplate()
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.Controls.StackPanel.StackMeasureHelper(IStackMeasure measureElement, IStackMeasureScrollData scrollData, Size constraint)
       at System.Windows.Controls.StackPanel.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.ContextLayoutManager.UpdateLayout()
       at System.Windows.UIElement.UpdateLayout()

    Inner Exception:

    XamlObjectWriterException: Missing key value on 'CompositeCollection' object.

     at System.Xaml.XamlObjectWriter.GetKeyFromInstance(Object instance, XamlType instanceType, IAddLineInfo lineInfo)
       at System.Xaml.XamlObjectWriter.Logic_DoAssignmentToParentCollection(ObjectWriterContext ctx)
       at System.Xaml.XamlObjectWriter.Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx)
       at System.Xaml.XamlObjectWriter.WriteEndObject()
       at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
       at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)

    Compiled the application works just as before, but I cannot find a way to bind the data this way and get it to work in the designer using design data. I've built a small sample application that shows the problem and uploaded it to my Dropbox: https://www.dropbox.com/s/bv48alj0b35crxe/CompositeCollectionTest.zip?dl=0

    Any ideas how this problem can be solved?

    Freitag, 28. Juni 2019 09:55

Antworten

  • I guess I already found a solution for this. I've moved the CompositeCollection from the grid resources directly into the ItemSource property so it doesn't need a key anymore:

    <ListView Grid.Row="1">
      <ListView.ItemsSource>
        <CompositeCollection>
          <CollectionContainer Collection="{Binding Source={StaticResource GlobalViewSource}}" />
          <CollectionContainer Collection="{Binding Source={StaticResource ListViewItemSource}}" />
        </CompositeCollection>
      </ListView.ItemsSource>

      ......

    After that no design data was displayed, but I found a way to get it to work again by just adding this to the CollectionViewSource:

    d:Source="{Binding GlobalDataItems, Source={d:DesignInstance Type=local:TestDesignData, IsDesignTimeCreatable=True}}"

    Now every CollectionViewSource has it's own DesignInstance and for the sub items I simply created an additional property to get example items. Now everything works in the designer and in the compiled version.

    Freitag, 28. Juni 2019 12:20