Silverlight4就可以创建右键菜单,但是需要多加几个方法限制SL自带的右键菜单的显示。
在SL5里面创建右键菜单就相对简单一些,这里是写的一个通用方法的简单例子。
程序集 System.windows.Controls.input.Toolkit.dll
using System;using System.Net;using System.windows;using System.windows.Controls;using System.windows.documents;using System.windows.Ink;using System.windows.input;using System.windows.Media;using System.windows.Media.Animation;using System.windows.Shapes;namespace SinoChemBI.Tools{ public class RightmenuTools { #region 创建截图右键菜单菜单 public event EventHandler OnPrintScreenMenuItemClick; ///<summary> /// 创建截图右键菜单菜单 ///</summary> public voID CreatePrintScreenRightmenu(UIElement _UIElement) { ContextMenu newMenu = new ContextMenu(); MenuItem _PrintScreen = new MenuItem(); _PrintScreen.header = "另存为图片"; _PrintScreen.Click += (s,e) => { if (OnPrintScreenMenuItemClick != null) { OnPrintScreenMenuItemClick(_UIElement,e); } }; newMenu.Items.Add(_PrintScreen); ContextMenuService.SetContextMenu(_UIElement,newMenu);//为控件绑定右键菜单 } #endregion }}
使用方法:
/// <summary> /// 初始化加载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> voID WorkloadStatistics_Loaded(object sender,RoutedEventArgs e) { //绑定右键菜单 RightmenuTools _RightmenuTools1 = new RightmenuTools(); _RightmenuTools1.OnPrintScreenMenuItemClick += new EventHandler(_RightmenuTools1_OnPrintScreenMenuItemClick); _RightmenuTools1.CreatePrintScreenRightmenu(Paretochart1); //LoadData(); } voID _RightmenuTools1_OnPrintScreenMenuItemClick(object sender,EventArgs e) { bool? _IsSuccess = _Imagetools.PrintScreen(this.Paretochart1);//这里调用的是我上一篇博客中的截图工具类 if (_IsSuccess == true) { MessageBox.Show("保存成功"); } else if (_IsSuccess == false) { MessageBox.Show("保存失败"); } }总结
以上是内存溢出为你收集整理的Silverlight5 创建右键菜单菜单全部内容,希望文章能够帮你解决Silverlight5 创建右键菜单菜单所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)