WPF菜单子项

时间:2014-10-10 11:56:51

标签: wpf vb.net xaml

给出以下xaml和对象结构:

<Menu ItemsSource="{Binding PageViewModels}" MouseEnter="Menu_MouseEnter" DockPanel.Dock="Top">
            <Menu.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Value}">
                    <TextBlock Text="{Binding Key}"></TextBlock>
                    <HierarchicalDataTemplate.ItemTemplate>
                        <DataTemplate>
                            <MenuItem Header="{Binding Name}" ItemsSource="{Binding MenuItems}">
                                <MenuItem.ItemTemplate>
                                    <HierarchicalDataTemplate ItemsSource="{Binding}">
                                        <HierarchicalDataTemplate.ItemTemplate>
                                            <DataTemplate>
                                                <TextBlock Text="{Binding Name}" />
                                            </DataTemplate>
                                        </HierarchicalDataTemplate.ItemTemplate>
                                    </HierarchicalDataTemplate>
                                </MenuItem.ItemTemplate>
                            </MenuItem>
                        </DataTemplate>
                    </HierarchicalDataTemplate.ItemTemplate>
                </HierarchicalDataTemplate>
            </Menu.ItemTemplate>
        </Menu>

查看模型对象:

Public Class MenuItemViewModel

        Private _name As String
        Private _parentName As String
        Private _objType As Type

        Public Sub New(name As String, parentName As String, objType As Type)
            _name = name
            _parentName = parentName
            _objType = objType
        End Sub

        Public ReadOnly Property Name As String
            Get
                Return _name
            End Get
        End Property

        Public ReadOnly Property ParentName As String
            Get
                Return _parentName
            End Get
        End Property

        Public ReadOnly Property ObjectType As Type
            Get
                Return _objType
            End Get
        End Property

        Public Property MenuItems As New ObservableCollection(Of MenuItemViewModel)

    End Class

...

Public ReadOnly Property PageViewModels As Dictionary(Of String, List(Of MenuItemViewModel))

我无法显示子菜单的菜单:

enter image description here

我确定我的xaml不正确,否则它会起作用所以任何帮助都会受到赞赏!

0 个答案:

没有答案