Fork me on GitHub

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>
复制代码

 

posted @   种花生的读书人  阅读(1412)  评论(0)    收藏  举报
编辑推荐:
· 糊涂啊!这个需求居然没想到用时间轮来解决
· 浅谈为什么我讨厌分布式事务
· 在 .NET 中使用内存映射文件构建高性能的进程间通信队列
· 一个 java 空指针异常的解决过程
· 揭开 SQL Server 和 PostgreSQL 填充因子的神秘面纱
阅读排行:
· 从硬盘爆满到 GitHub 封号,一位前端开发者的开源历险记
· 微软又一自动化开源王炸,Selenium 慌了!
· 微服务的10大问题
· C#解析JSON数据全攻略
· 上周热点回顾(7.14-7.20)

该博客仅作为记录笔记,转载随意

点击右上角即可分享
微信分享提示