繁体   English   中英

WPF-需要结合使用Tree + Grid和上下文菜单

[英]WPF - Need a combination of Tree+Grid, with Context Menu

我的应用程序是通过TreeListGridView实现的。

在此处输入图片说明

令我感到绝望的是,与广泛使用的DataGrid相比,GridView非常原始。 我正在考虑以下两种选择:

(1)不知何故,我将GridView替换为DataGrid(支持Context Menu)。

(2)不知何故,我将上下文菜单功能添加到了现有的GridView中。

您会推荐两种方法中的哪一种(或另一种?)?

源代码非常受赞赏。

TIA。

根据链接的代码,以下是解决方案:

1-将ContextMenu添加为资源:

<Window.Resources>
    <ContextMenu x:Key="ItemsContextMenu" x:Shared="False">
        <MenuItem>
            <MenuItem.Header>
                <TextBlock>
                    <Run>Context Menu Action for Item</Run>
                    <Run Text="{Binding Tag.Name}"/>
                </TextBlock>
            </MenuItem.Header>
        </MenuItem>
    </ContextMenu>

    <!-- other stuff here -->

</Window.Resources>

建议您设置x:Shared="False"以防止与重用资源实例有关的绑定问题。

2 -定义ItemContainerStyle您的TreeList该设置文本菜单的TreeListItem S:

<tree:TreeList ...>
    <!-- other stuff here -->

    <tree:TreeList.ItemContainerStyle>
        <Style TargetType="{x:Type tree:TreeListItem}">
            <Setter Property="ContextMenu" Value="{StaticResource ItemsContextMenu}"/>
         </Style>
    </tree:TreeList.ItemContainerStyle>
</tree:TreeList>

请注意,我在ContextMenu使用了DataBinding,这意味着您在其中具有适当的,可以正常工作的DataContext 您应该可以使用其中的Commands和其他内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM