views:

211

answers:

1

I have a UserControl which contains a ListBox. And ListBox uses another UserControl as DataTemplate.

    <ListBox x:Uid="SectionList" x:Name="SectionList" ItemsSource="{Binding}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <expander:ExpanderDataTemplate/>
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

In the code behind I set the data context to ObservableCollection. ExpanderItem exposes following public properties... string Name, ObservableCollection MenuItems, bool Expanded, UserControl Control I have implemented INotifyPropertyChanged interface for these properties.

And my ExpanderDataTemplate looks like this...

<Border BorderThickness="0,1">
    <Expander IsExpanded="{Binding Path=Expanded}" Content="{Binding Path=Control}">
        <Expander.Header>
            <StackPanel>
                <TextBlock Text="{Binding Path=Name}"/>
                <Menu x:Name="ConfigurationMenu" Background="Transparent">
                    <MenuItem x:Name="DropDownMenuItem" ItemsSource="{Binding Path=MenuItems}">
                        <MenuItem.Header>
                            <Image Source="..\..\images\dropdown_arrow.gif" SnapsToDevicePixels="True" Stretch="None"/>
                        </MenuItem.Header>
                    </MenuItem>
                </Menu>
            </StackPanel>
        </Expander.Header>
    </Expander>
</Border>

Here, you can see that I have data bounded all four properties Expanded, Control, Name and MenuItems. All properties are getting bounded properly and visible expect MenuItems. MenuItems is ObservableCollection of System.Windows.Controls.MenuItem.

I want to achieve the desired behavior when I click the DropDownMenuItem, I should see the data bounded MenuItems collection as submenu.

Please help me on this. Thank you.

A: 

Thanks for your response Aran.

Nevermind, there was a small mistake from my code behind. I was not setting up MenuItems collection properly. It is working fine now. Thanks.

Rajiv
can you answer with your code behind so the rest of us can see the solution?
Maslow