WPF-控件-层级控件-Menu-嵌套结构
<?xml version="1.0" encoding="utf-8" ?> <Data xmlns=""> <Operation Name="文件" Gesture="F"> <Operation Name="新建" Gesture="N"> <Operation Name="项目" Gesture="Control + P"/> <Operation Name="网站" Gesture="Control + W"/> <Operation Name="文档" Gesture="Control + D"/> </Operation> <Operation Name="保存" Gesture="S"/> <Operation Name="打印" Gesture="P"/> <Operation Name="退出" Gesture="X"/> </Operation> <Operation Name="编辑" Gesture="E"> <Operation Name="拷贝" Gesture="Control + C"/> <Operation Name="剪切" Gesture="Control + X"/> <Operation Name="粘贴" Gesture="Control + S"/> </Operation> </Data>
<Window x:Class="工具栏功能的样式.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <!--数据源--> <XmlDataProvider x:Key="Ds" Source="Data.xml" XPath="Data/Operation"/> <!--Operation模板--> <HierarchicalDataTemplate DataType="Operation" ItemsSource="{Binding XPath=Operation}"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding XPath=@Name}" Margin="10,0"/> <TextBlock Text="{Binding XPath=@Gesture}"/> </StackPanel> </HierarchicalDataTemplate> </Window.Resources> <StackPanel> <Menu ItemsSource="{Binding Source={StaticResource Ds}}"></Menu> </StackPanel> </Window>