原文:WPF中的菜单模板

资源字典代码如下:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <!--Menu控件模板-->
<ControlTemplate x:Key="mycontroltemplate" TargetType="{x:Type Menu}">
<Border Margin="2"
Background="Chocolate"
CornerRadius="3"
SnapsToDevicePixels="True">
<ItemsPresenter/>
</Border>
</ControlTemplate> <!--MenuItem控件模板-->
<ControlTemplate x:Key="mymenuitemtemplate"
TargetType="MenuItem">
<Border Name="Border">
<Grid>
<ContentPresenter
Margin="10"
ContentSource="Header"
RecognizesAccessKey="True"/>
<Popup
AllowsTransparency="True"
Name="Popup"
Placement="Top"
IsOpen="{TemplateBinding IsSubmenuOpen}"
Focusable="False"
PopupAnimation="Slide">
<Border
CornerRadius="30"
Name="SubmenuBorder"
SnapsToDevicePixels="True">
<StackPanel
IsItemsHost="True"
KeyboardNavigation.DirectionalNavigation="Cycle" />
<Border.Background>
<DrawingBrush>
<DrawingBrush.Drawing>
<GeometryDrawing Brush="YellowGreen">
<GeometryDrawing.Geometry>
<CombinedGeometry GeometryCombineMode="Exclude">
<CombinedGeometry.Geometry1>
<EllipseGeometry RadiusX="20" RadiusY="20"/>
</CombinedGeometry.Geometry1>
<CombinedGeometry.Geometry2>
<EllipseGeometry RadiusX="10" RadiusY="10"/>
</CombinedGeometry.Geometry2>
</CombinedGeometry>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</Border.Background>
</Border>
</Popup>
</Grid>
</Border>
<!--可有可无________________________________________________________________________________-->
<!--<ControlTemplate.Triggers>
<Trigger Property="IsSuspendingPopupAnimation" Value="true">
<Setter TargetName="Popup" Property="PopupAnimation" Value="None"/>
</Trigger>
<Trigger Property="IsHighlighted" Value="true">
<Setter TargetName="Border" Property="Background"
Value="Transparent"/>
<Setter TargetName="Border" Property="BorderBrush"
Value="Transparent"/>
</Trigger>
<Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="True">
<Setter TargetName="SubmenuBorder" Property="CornerRadius" Value="0,0,4,4"/>
<Setter TargetName="SubmenuBorder" Property="Padding" Value="0,0,0,3"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="Black"/>
</Trigger>
</ControlTemplate.Triggers>-->
<!--可有可无________________________________________________________________________________-->
</ControlTemplate> </ResourceDictionary> 窗体XAML代码如下: <Window x:Class="WPF中的菜单模板.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MyDictionary/MyDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<DockPanel>
<Menu DockPanel.Dock="Bottom"
Template="{StaticResource mycontroltemplate}">
<MenuItem Header="开始">
<MenuItem Header="开始"></MenuItem>
<MenuItem Header="开始"></MenuItem>
<MenuItem Header="开始"></MenuItem>
<MenuItem Header="开始"></MenuItem>
</MenuItem>
<Menu.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}">
<Setter Property="Template" Value="{StaticResource mymenuitemtemplate}"/>
</Style>
</Menu.ItemContainerStyle>
</Menu>
<Popup></Popup>
</DockPanel>
</Window>

WPF中的菜单模板的更多相关文章

  1. WPF 中获取DataGrid 模板列中控件的对像

    WPF 中获取DataGrid 模板列中控件的对像 #region 当前选定行的TextBox获得焦点 /// <summary> /// 当前选定行的TextBox获得焦点 /// &l ...

  2. WPF中的数据模板(DataTemplate)(转)

    原文地址 http://www.cnblogs.com/zhouyinhui/archive/2007/03/30/694388.html WPF中的数据模板(DataTemplate)        ...

  3. WPF中的数据模板(DataTemplate)

    原文:WPF中的数据模板(DataTemplate) WPF中的数据模板(DataTemplate)                                                   ...

  4. WPF中的数据模板使用方式之一:ContentControl、ContentTemplate和TemplateSelector的使用

    在WPF中,数据模板是非常强大的工具,他是一块定义如何显示绑定的对象的XAML标记.有两种类型的控件支持数据模板:(1)内容控件通过ContentTemplate属性支持数据模板:(2)列表控件通过I ...

  5. wpf中的数据模板

    wpf中的模板分为数据模板和控件模板,我们可以通过我们自己定制的数据模板来制定自己想要的数据表现形式.例如:时间的显示可以通过图片,也可以通过简单数字表现出来. 例如: (1)先在Demo这个命名空间 ...

  6. 如何在WPF中定义窗体模板

    参考网址:https://www.cnblogs.com/chenxizhang/archive/2010/01/10/1643676.html可以在app.xaml中定义一个ControlTempl ...

  7. 在WPF中获取DataGridTemplateColumn模板定义的内容控件

    xaml格式描述: <DataGrid Name="dataGrid" Grid.Row="1" ItemsSource="{Binding}& ...

  8. 在WPF中获取DATAGRIDTEMPLATECOLUMN模板定义的内容控件(转载)

    原文:http://www.cnblogs.com/eric_ibm/p/3772516.html xaml格式描述: <DataGrid Name="dataGrid" G ...

  9. WPF中Expander的用法和控件模板详解

    一.Expander的用法 在WPF中,Expander是一个很实用的复合控件,可以很方便的实现下拉菜单和导航栏等功能.先介绍简单的用法,而后分析他的控件模板. <Window.Resource ...

随机推荐

  1. 如何在 Linux 中统计一个进程的线程数

    编译自:http://ask.xmodulo.com/number-of-threads-process-linux.html作者: Dan Nanni原创:LCTT https://linux.cn ...

  2. [AngularFire2] Build a Custom Node Backend Using Firebase Queue

    In this lesson we are going to learn how to build a custom Node process for batch processing of Fire ...

  3. Android 闹钟最终版

    以下是我发现的几点闹钟中重要的点,分享一下: (1)在闹钟中有AudioManager管理机制,这个机制可以申请和释放OnAudioFocusChangeListener监听. 还有mTelephon ...

  4. [GraphQL] Create an Input Object Type for Complex Mutations

    When we have certain mutations that require more complex input parameters, we can leverage the Input ...

  5. .net core 微服务之Api网关(Api Gateway)

    原文:.net core 微服务之Api网关(Api Gateway) 微服务网关目录 1. 微服务引子 2.使用Nginx作为api网关 3.自创api网关(重复轮子) 3.1.构建初始化 3.2. ...

  6. Web开发四大作用域(转)

    Web开发中的四个域对象(范围由小到大): page(jsp有效)  request(一次请求) session(一次会话) application(当前web应用) page域指的是pageCont ...

  7. 使用PowerDesigner15在win7下的系统MySQL p相反roject(一)

    使用PowerDesigner15在win7下的系统MySQL 相反project 1.首先.安装下面的驱动 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv ...

  8. c++ try catch 问题(没有throw就会被删除,加上/EHa这样就不会被删除)

    以前都是用try{} catch(…){}来捕获C++中一些意想不到的异常, 今天看了Winhack的帖子才知道,这种方法在VC中其实是靠不住的.例如下面的代码: 以前都是用try{} catch(… ...

  9. 【a202】&&【9208】输油管道问题

    Time Limit: 10 second Memory Limit: 2 MB 问题描述 某石油公司计划建造一条由东向西的主输油管道.该管道要穿过一个有n 口油井的油 田.从每口油井都要有一条输油管 ...

  10. Mapreduce 订单分组案例

    程序执行流程如下: map()-->getPartition()分区--->write()(序列化,每一行都顺序执行这三个方法)--->readFields()---->com ...