[英]WPF - Need a combination of Tree+Grid, with Context Menu
我的應用程序是通過TreeList
的GridView
實現的。
令我感到絕望的是,與廣泛使用的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.