开发者

Context sub menu with items source and additional items

I have a context menu in wpf. One of the items in the menu has a sub menu that gets populated from the ItemsSource of the header menu item. This sub menu is a list of commands that can be sent to another portion of the app. The list is basically a mru list restricted to 10 items. I want to add a separator and then a "More" option below the list of 10 items so the user can see the entire list of available commands. I can't seem to figure out how to add these extra items. I can get the list to populate dynamically from the ItemsSource of the parent menu item but I can't seem to figure out how to add the additional items to the bottom of the child menu. I don't want to put them in the items source and the "More" item needs to have its own command.

<MenuItem x:Name="ExecuteCommandMenuItem" Height="22" Style="{StaticResource RightClickMenuItemStyle}"
                          ItemsSource="{Binding Path=PanelCommands}">
                    <MenuItem.Header>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Panel Command" HorizontalAlignment="Left" Width="100"/>
                        </StackPanel>
                    </MenuItem开发者_开发百科.Header>

                    <MenuItem.ItemContainerStyle>
                        <Style TargetType="MenuItem" BasedOn="{StaticResource RightClickMenuItemStyle}">
                            <Setter Property="MenuItem.Header" Value="{Binding}" />
                            <Setter Property="MenuItem.Command" Value="CommonCommands:CommandRepository.ExecutePanelCommand" />
                            <Setter Property="MenuItem.CommandParameter">
                                <Setter.Value>
                                    <MultiBinding Converter="{CommonConverter:PanelCommandArgsConverter}">
                                        <MultiBinding.Bindings>
                                            <Binding Path="DataContext" RelativeSource="{RelativeSource FindAncestor, 
                                                             AncestorType={x:Type ContextMenu}}"/>
                                            <Binding Path="Command" />
                                        </MultiBinding.Bindings>
                                    </MultiBinding>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </MenuItem.ItemContainerStyle>
                </MenuItem>

Thanks.


<DataGrid x:Class="UICCNET.BaseControls.UserControls.BaseDataGrid"
         Tag="{Binding RelativeSource={RelativeSource Self}, Path=Columns}">
<DataGrid.ContextMenu>
    <ContextMenu Tag="{Binding RelativeSource={RelativeSource Self},Path=PlacementTarget.Tag}">
        <MenuItem Header="Колонки">
        <MenuItem  >              
            <MenuItem.Template>
                <ControlTemplate>
                        <ListBox  Name="MyComboBox"  ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}},Path=Tag}">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <CheckBox IsChecked="{Binding Path=Visibility, Mode=TwoWay, Converter={StaticResource BooleanToVisibilityConverter1}}" Content="{Binding Path=Header}"></CheckBox>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </ControlTemplate>
            </MenuItem.Template>
                 </MenuItem>
        </MenuItem>
        <MenuItem Header="Друк"></MenuItem>
    </ContextMenu>
</DataGrid.ContextMenu>


I dont think you can because it's bound to a source. So either add them to the source OR use a templateselector and do your logic in there. Define a normal template and then a "more" template.

Or, you can do some control nesting like

<menu>
<stackpanel>
<Menu Items>

</menu Items>
<break />
<Button>More</button>
</stackpanel>
</menu>

Sorry this is just off the top of my head. Can you post your XAML?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜