Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WCF and WF
  4. Composite Collection binding problem [modified]

Composite Collection binding problem [modified]

Scheduled Pinned Locked Moved WCF and WF
helpquestionwpfwcfdata-structures
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gnjunge
    wrote on last edited by
    #1

    EDIT: A workaround for this issue could be changing the question to : How do I add a default item to my databound listbox? Hello, I have the following code:

    <ListBox>
    <ListBox.ItemsSource>
    <CompositeCollection>
    <ListBoxItem>
    <StackPanel>
    <Image Source="Resources\nottagged.png" Height="15" Width="14"/>
    <TextBlock Margin="5,0">Not tagged</TextBlock>
    </StackPanel>
    </ListBoxItem>
    <CollectionContainer Collection="{Binding Path=Manager.Tags}" />
    </CompositeCollection>
    </ListBox.ItemsSource>
    </ListBox>

    This doesn't work, in the output it writes: System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Manager.Tags; DataItem=null; target element is 'CollectionContainer' (HashCode=30880833); target property is 'Collection' (type 'IEnumerable') There is nothing wrong with the binding because this does work (only i miss my custom ListBoxItem, that is not contained in the collection):

    <ListBox ItemsSource="{Binding Path=Manager.Tags}" />

    Binding it to an array of Tag object defined in the resources does work, but of course is not what I need :

    <x:Array x:Key="data2" Type="{x:Type data:Tag}" >
    <data:Tag Name="Tag1"/>
    <data:Tag Name="Tag2"/>
    <data:Tag Name="Tag3"/>
    </x:Array>

    with the following replacement in the code sample above:

    <CollectionContainer Collection="{StaticResource data2}" />

    I did some searches on the internet, found some posts, but they were quite old and vague. Does somebody have a solution for this? Thanks al lot, Gidon

    modified on Sunday, May 18, 2008 9:49 AM

    C 1 Reply Last reply
    0
    • G gnjunge

      EDIT: A workaround for this issue could be changing the question to : How do I add a default item to my databound listbox? Hello, I have the following code:

      <ListBox>
      <ListBox.ItemsSource>
      <CompositeCollection>
      <ListBoxItem>
      <StackPanel>
      <Image Source="Resources\nottagged.png" Height="15" Width="14"/>
      <TextBlock Margin="5,0">Not tagged</TextBlock>
      </StackPanel>
      </ListBoxItem>
      <CollectionContainer Collection="{Binding Path=Manager.Tags}" />
      </CompositeCollection>
      </ListBox.ItemsSource>
      </ListBox>

      This doesn't work, in the output it writes: System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Manager.Tags; DataItem=null; target element is 'CollectionContainer' (HashCode=30880833); target property is 'Collection' (type 'IEnumerable') There is nothing wrong with the binding because this does work (only i miss my custom ListBoxItem, that is not contained in the collection):

      <ListBox ItemsSource="{Binding Path=Manager.Tags}" />

      Binding it to an array of Tag object defined in the resources does work, but of course is not what I need :

      <x:Array x:Key="data2" Type="{x:Type data:Tag}" >
      <data:Tag Name="Tag1"/>
      <data:Tag Name="Tag2"/>
      <data:Tag Name="Tag3"/>
      </x:Array>

      with the following replacement in the code sample above:

      <CollectionContainer Collection="{StaticResource data2}" />

      I did some searches on the internet, found some posts, but they were quite old and vague. Does somebody have a solution for this? Thanks al lot, Gidon

      modified on Sunday, May 18, 2008 9:49 AM

      C Offline
      C Offline
      cybice
      wrote on last edited by
      #2

      Have you find solution?

      G 1 Reply Last reply
      0
      • C cybice

        Have you find solution?

        G Offline
        G Offline
        gnjunge
        wrote on last edited by
        #3

        No I didn't. I also stopped momentarily with the project for which I needed it for. So come to making a workaround.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups