8,737
社区成员
发帖
与我相关
我的任务
分享
<Window x:Class="BdmsPlatform.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Name="frmMainWindow" Height="600" Width="800">
<Grid Name="grdMain">
<Grid.RowDefinitions>
<RowDefinition Name="grdRow0" Height="30"></RowDefinition>
<RowDefinition Name="grdRow1" Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Menu HorizontalAlignment="Right" Name="menuMain"
Height="{Binding ElementName=grdRow0, Path=Height}"
Grid.Row="0" Grid.Column="0"
Width="{Binding ElementName=frmMainWindow, Path=Width}"
Margin="0,0,-8,0"
>
<Menu.ItemTemplate>
<DataTemplate>
<MenuItem ItemsSource="{Binding Path=Items}" Height="{Binding ElementName=menuMain,Path=Height}" FontSize="15"
Header="{Binding Path=Title}">
<MenuItem.ItemTemplate>
<DataTemplate>
<MenuItem Height="{Binding ElementName=menuMain,Path=Height}" FontSize="15"
Header="{Binding Path=Title}">
</MenuItem>
</DataTemplate>
</MenuItem.ItemTemplate>
</MenuItem>
</DataTemplate>
</Menu.ItemTemplate>
</Menu>
</Grid>
</Window>
public partial class MainWindow : Window
{
// public BdmsInterface.MenuItem[] menus { get; set; }
public MainWindow()
{
InitializeComponent();
BdmsInterface.MenuItem[] menus = new BdmsInterface.MenuItem[]{
new BdmsInterface.MenuItem("系统","S"),
new BdmsInterface. MenuItem("项目","X"),
new BdmsInterface.MenuItem("工具","T")
};
menus[0].Items.Add(new BdmsInterface.MenuItem("退出", "X"));
this.menuMain.ItemsSource = menus;
}
}
namespace BdmsInterface
{
public class MenuItem
{
public string Name { get; set; }
public string Title { get; set; }
public string Key { get; set; }
public string Command { get; set; }
public List<MenuItem> Items { get; private set; }
public MenuItem()
{
Items = new List<MenuItem>();
}
public MenuItem(string Title, string Key):this()
{
this.Title = Title;
this.Key = Key;
}
}
}