我正在开发一个 WPF 项目,以下是我的 Menu 数据模型的代码
class NavigationMenu
{
public abstract class MenuBase
{
public MenuBase()
{
}
public MenuBase(string title)
{
MenuTitle = title;
}
public Guid MenuId { get; set; }
public string MenuTitle { get; set; }
public string ImageResourceName { get; set; }
}
public class MenuItem : MenuBase
{
public MenuItem()
{
}
public MenuItem(string title)
: base(title)
{
}
public string View { get; set; }
}
public class MenuCategory : MenuBase
{
public MenuCategory()
{
MenuItems = new ObservableCollection<MenuItem>();
}
public MenuCategory(string title)
: base(title)
{
MenuItems = new ObservableCollection<MenuItem>();
}
public MenuCategory(string CategoryTitle, ObservableCollection<MenuItem> pMenuItems)
: base(CategoryTitle)
{
this.MenuItems = pMenuItems;
}
public ObservableCollection<MenuItem> MenuItems { get; set; }
}
public class MainMenuItem : MenuBase
{
public MainMenuItem()
{
MenuCategories = new ObservableCollection<MenuCategory>();
}
public MainMenuItem(string title)
: base(title)
{
MenuCategories = new ObservableCollection<MenuCategory>();
}
public ObservableCollection<MenuCategory> MenuCategories { get; set; }
}
}
XAMLRadMenu
如下,
<ui:RadMenu Name="radMenu1" ItemsSource="{Binding MenuBar}" Height="76">
<ui:RadMenu.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Path=MenuCategories}">
<StackPanel Height="Auto">
<Image MaxWidth="32" MaxHeight="32" Source="{Binding Path=ImageResourceName}" />
<TextBlock HorizontalAlignment="Center">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource myConv}">
<Binding Path="MenuId"></Binding>
<Binding Path="MenuTitle"></Binding>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</HierarchicalDataTemplate>
</ui:RadMenu.ItemTemplate>
</ui:RadMenu>
我遇到的问题是,MenuCategories 显示成功,但MenuItems
内部MenuCategory
没有显示。很明显,我没有绑定MenuItems
但是MenuCategories
. 但我不确定如何MenuItems
在上面绑定DataTemplate
?任何想法?