SilverLight4 右键菜单和悬停框
在Silverlight4之前,要是想使用右键菜单,只能采用自己模拟的方法,但是这个方法必须将windowless属性设置成true。但是,一旦windowless属性被设置成true的话,Silverlight画面中的所有TextBox控件里就不能输入中文了。为此将项目从vs2008升级到VS2010,直接使用Silverlight4中的右键菜单功能。
下边是我在实际开发中给一个STACKPANEL添加右键菜单和悬浮提示框的代码
public void DrawPanel()
{
//
StackPanel mPanel = new StackPanel();
//悬浮提示
StackPanel tipmPanel = new StackPanel();
tipmPanel.Orientation = Orientation.Vertical;
TextBlock txtPlan = new TextBlock();
txtPlan.FontWeight = FontWeights.Bold;
txtPlan.Text = "我在悬浮";
tipmPanel.Children.Add(txtPlan);
ToolTipService.SetToolTip(mPanel, tipmPanel);
ContextMenu cm = new ContextMenu();
//
MenuItem mEditPlan = new MenuItem();//新建右键菜单项
mEditPlan.Header = "编辑";
mEditPlan.Click += mEditPlan_Click;//为菜单项注册事件
cm.Items.Add(mEditPlan);
//
ContextMenuService.SetContextMenu(mPanel, cm);//为控件绑定右键菜单
}
protected void mEditPlan_Click(object sender, RoutedEventArgs e)
{
//....
}
推荐.NET配套的通用数据层ORM框架:CYQ.Data 通用数据层框架