WPF中的菜单模板
原文: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中的菜单模板的更多相关文章
- WPF 中获取DataGrid 模板列中控件的对像
WPF 中获取DataGrid 模板列中控件的对像 #region 当前选定行的TextBox获得焦点 /// <summary> /// 当前选定行的TextBox获得焦点 /// &l ...
- WPF中的数据模板(DataTemplate)(转)
原文地址 http://www.cnblogs.com/zhouyinhui/archive/2007/03/30/694388.html WPF中的数据模板(DataTemplate) ...
- WPF中的数据模板(DataTemplate)
原文:WPF中的数据模板(DataTemplate) WPF中的数据模板(DataTemplate) ...
- WPF中的数据模板使用方式之一:ContentControl、ContentTemplate和TemplateSelector的使用
在WPF中,数据模板是非常强大的工具,他是一块定义如何显示绑定的对象的XAML标记.有两种类型的控件支持数据模板:(1)内容控件通过ContentTemplate属性支持数据模板:(2)列表控件通过I ...
- wpf中的数据模板
wpf中的模板分为数据模板和控件模板,我们可以通过我们自己定制的数据模板来制定自己想要的数据表现形式.例如:时间的显示可以通过图片,也可以通过简单数字表现出来. 例如: (1)先在Demo这个命名空间 ...
- 如何在WPF中定义窗体模板
参考网址:https://www.cnblogs.com/chenxizhang/archive/2010/01/10/1643676.html可以在app.xaml中定义一个ControlTempl ...
- 在WPF中获取DataGridTemplateColumn模板定义的内容控件
xaml格式描述: <DataGrid Name="dataGrid" Grid.Row="1" ItemsSource="{Binding}& ...
- 在WPF中获取DATAGRIDTEMPLATECOLUMN模板定义的内容控件(转载)
原文:http://www.cnblogs.com/eric_ibm/p/3772516.html xaml格式描述: <DataGrid Name="dataGrid" G ...
- WPF中Expander的用法和控件模板详解
一.Expander的用法 在WPF中,Expander是一个很实用的复合控件,可以很方便的实现下拉菜单和导航栏等功能.先介绍简单的用法,而后分析他的控件模板. <Window.Resource ...
随机推荐
- HDU 1248 寒冰王座 完全背包
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1248 中文题,大意就不说了. 第一道完全背包题,跟着背包九讲做的. 和0-1背包的区别在于所不同的是每种 ...
- 【Codeforces Round #439 (Div. 2) B】The Eternal Immortality
[链接] 链接 [题意] 求b!/a!的最后一位数字 [题解] b-a>=20的话 a+1..b之间肯定有因子2和因子5 答案一定是0 否则暴力就好 [错的次数] 在这里输入错的次数 [反思] ...
- (八)RabbitMQ消息队列-通过Topic主题模式分发消息
原文:(八)RabbitMQ消息队列-通过Topic主题模式分发消息 前两章我们讲了RabbitMQ的direct模式和fanout模式,本章介绍topic主题模式的应用.如果对direct模式下通过 ...
- Android JAVA中的时间大小比较
import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; imp ...
- Java基本数据类型之间赋值与运算归纳
前言:面对“byte b1=3;byteb2=7;byte b=b1+b2;”报错,而“int i1=3;int i2=7;int i=i1+i2;”不报错,进行了深入探究,从而引申出java基本类型 ...
- html5-2 html实体和颜色有哪些
html5-2 html实体和颜色有哪些 一.总结 一句话总结:网站配色用安全色. 1.颜色用什么类型的颜色(安全色)? 直接百度搜 安全色 即可 2.html实体常用哪6个,头尾符号是什么? 头是取 ...
- 【hdu5692】Snacks
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submissio ...
- python3 numpy API练习代码
# -*- coding: utf-8 -*- import numpy as np; a=np.array([1,2,3,4,5,6]); print("数组是:",a) #数组 ...
- System.nanoTime()和System.currentTimeMillis()性能问题
之前给模块做性能优化的时候,需要将性能调到毫秒级,使用了System.nanoTime()和System.currentTimeMillis()对代码分片计时分析耗时操作,后发现在串行情况下性能达 ...
- centos7 firewall-cmd查看端口是否开放及开放端口
查询端口号80 是否开启:firewall-cmd /tcp 永久开放80端口号:firewall-cmd --permanent --zone=public /tcp 移除80端口号:/tcp -- ...