Answered How to use CollectionContainer as ItemsSource?

  • Thursday, March 24, 2011 9:30 AM
     
      Has Code

    Hello,

    I have a small code sample that works fine

    <ContextMenu ItemsSource="{BindingPath=AvailableViews}">

    AvailableViews is an ObservableCollection.

    If I like to extend it in the following way it dosn't work, the contextMenue appears empty:

    <ContextMenu>
      <ContextMenu.ItemsSource>
        <CompositeCollection>
          <CollectionContainer Collection="{Binding Path=AvailableViews}" />
        </CompositeCollection>
      </ContextMenu.ItemsSource>
    </ContextMenu>
    

    My question is: Why doesn't work the second code snippet?

    Roy

All Replies

  • Thursday, March 24, 2011 10:01 AM
     
     Answered
  • Friday, March 25, 2011 5:11 AM
    Moderator
     
     Answered Has Code

    Hi RMxxx,

    Thank you for this feedback, I will continue to consult internal for this issue. On the other hand, we have a workaround:

      <Window.Resources>
        <CollectionViewSource x:Key="source" Source="{Binding AvailableViews}"/>
      </Window.Resources>
      <Grid Background="Red">
        <Grid.ContextMenu>
          <!--<ContextMenu ItemsSource="{Binding Path=AvailableViews}"/>-->
          <ContextMenu>
            <ContextMenu.ItemsSource>
              <CompositeCollection>
                <CollectionContainer Collection="{Binding Source={StaticResource source}}" />
              </CompositeCollection>
            </ContextMenu.ItemsSource>
          </ContextMenu>
        </Grid.ContextMenu>
      </Grid>
    

     

    Please check it out.

     

    Sincerely,


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.