积极答复者
关于自定义Menu的问题

问题
-
这个是360杀毒的托盘菜单。我想知道 如果用WPF 实现类似效果的话,要怎么做呢?我知道的2种方法,一种是使用窗体来模拟。第二种是自定义menu。 所以一般会选择第二种来实现,那如果自定义menu的话。在哪里去看menu的API呢?怎么知道Menu的模板要如何来改呢?
我自己实现方法是,用一张图片来做背景。
图:
然后还要自定义MenuItem
最后还要处理MenuItem鼠标滑过的样式
对了,还要处理separator 就是那条横线。
但是我最大的问题就是,在哪里看Menu的模板?哪里有API可以看?让我知道Menu的模板该如何改成这个呢?或者大神 能给出类似的代码参考赶集不尽。
晕死,居然提示 发不了图片
- 在我们能够验证您的帐户前,正文文本不能包含图片和链接。
答案
-
你好,
>>在哪里去看menu的API呢?怎么知道Menu的模板要如何来改呢?
在这里,我们需要自定义 ContextMenu的模板,请见以下MSDN文档:
#ContextMenu Overview
http://msdn.microsoft.com/en-us/library/ms742558(v=vs.110).aspx#ContextMenu Styles and Templates
http://msdn.microsoft.com/en-us/library/ms744758(v=vs.110).aspx>>然后还要自定义MenuItem 最后还要处理MenuItem鼠标滑过的样式
对MenuItem应用Trigger即可,具体如何自定义它的模板,请见:
#MenuItem ControlTemplate Example
http://msdn.microsoft.com/en-us/library/ms747082(v=vs.85).aspx>>对了,还要处理separator 就是那条横线。
同样通过自定义模板实现,我的示例是去自定义为虚线:
<Style x:Key="MySeparator" TargetType="Separator"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Separator"> <Grid SnapsToDevicePixels="True" Margin="0,6,0,4"> <Rectangle Stroke="#FF000000" Height="1" StrokeThickness="1" StrokeDashArray="4 4" SnapsToDevicePixels="True"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
结合文档中的一些示例代码,加上自定义的ImageBrush(背景图片)及一些其他自定义,我的示例程序效果如下:
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 Franklin ChenMicrosoft employee, Moderator 2014年7月3日 10:22
-
可以把你这个Demo发给我吗?我的email
你好,
你可以从以下链接下载我的Demo: http://1drv.ms/1sPWUPY
建议不要在论坛留私人邮箱,防止泄露个人信息:)
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已建议为答案 Leo (Apple) YangModerator 2014年7月1日 7:33
- 已标记为答案 Franklin ChenMicrosoft employee, Moderator 2014年7月3日 10:22
全部回复
-
你好,
>>在哪里去看menu的API呢?怎么知道Menu的模板要如何来改呢?
在这里,我们需要自定义 ContextMenu的模板,请见以下MSDN文档:
#ContextMenu Overview
http://msdn.microsoft.com/en-us/library/ms742558(v=vs.110).aspx#ContextMenu Styles and Templates
http://msdn.microsoft.com/en-us/library/ms744758(v=vs.110).aspx>>然后还要自定义MenuItem 最后还要处理MenuItem鼠标滑过的样式
对MenuItem应用Trigger即可,具体如何自定义它的模板,请见:
#MenuItem ControlTemplate Example
http://msdn.microsoft.com/en-us/library/ms747082(v=vs.85).aspx>>对了,还要处理separator 就是那条横线。
同样通过自定义模板实现,我的示例是去自定义为虚线:
<Style x:Key="MySeparator" TargetType="Separator"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Separator"> <Grid SnapsToDevicePixels="True" Margin="0,6,0,4"> <Rectangle Stroke="#FF000000" Height="1" StrokeThickness="1" StrokeDashArray="4 4" SnapsToDevicePixels="True"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
结合文档中的一些示例代码,加上自定义的ImageBrush(背景图片)及一些其他自定义,我的示例程序效果如下:
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 Franklin ChenMicrosoft employee, Moderator 2014年7月3日 10:22
-
可以把你这个Demo发给我吗?我的email
- 已编辑 Franklin ChenMicrosoft employee, Moderator 2014年6月30日 2:03 删除私人信息
-
可以把你这个Demo发给我吗?我的email
你好,
你可以从以下链接下载我的Demo: http://1drv.ms/1sPWUPY
建议不要在论坛留私人邮箱,防止泄露个人信息:)
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已建议为答案 Leo (Apple) YangModerator 2014年7月1日 7:33
- 已标记为答案 Franklin ChenMicrosoft employee, Moderator 2014年7月3日 10:22