silverlight右键菜单实现
来源:互联网 发布:tcl电视直播软件下载 编辑:程序博客网 时间:2024/05/16 06:33
1.添加一个<TextBlock>到Page.xaml中
<UserControl x:Class="rightClick.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<TextBlock x:Name="MyField">Right click please.</TextBlock>
</Grid>
</UserControl>
2.在页面中设置silverlight的参数Windowless="true" (这一点是最关键的!!!!!)
<asp:Silverlight ID="Silverlight1" runat="server" Height="480px"
MinimumVersion="2.0.30523" Source="~/ClientBin/rightClick.xap"
Windowless="true" Width="640px" />
<object data="data:application/x-silverlight," type="application/x-silverlight-2-b2" width="100%" height="100%">
<param name="source" value="ClientBin/rightClick.xap"/>
<param name="onerror" value="onSilverlightError" />
<param name="background" value="white" />
<param name="Windowless" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=115261" style="text-decoration: none;">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
</a>
</object>
3.最后修改Page.xaml.cs页面的代码
新建立一个ContextMenuInterceptor类.这个类是用来处理页面中“OnContextMenu”事件的.在用到HTMLPage对象你需要引入System.Window.Browser命名空间.
在调用e.PeventDefault()方法后,将会取消右键点击事件.所以silverlight不会捕捉到它.
在这里我们已经成功的拦截了右键点击事件,做我们想做的任何事情了.;)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Browser;
namespace rightClick
{
public partial class Page : UserControl
{
ContextMenuInterceptor _cmi = null;
public Page()
{
InitializeComponent();
_cmi = new ContextMenuInterceptor(MyField);
}
}
public class ContextMenuInterceptor
{
TextBlock TextField;
public ContextMenuInterceptor(TextBlock textField)
{
TextField = textField;
HtmlPage.Document.AttachEvent("oncontextmenu", this.OnContextMenu);
}
private void OnContextMenu(object sender, HtmlEventArgs e)
{
TextField.Text = "Right Clicked Blocked at " + e.OffsetX + "," + e.OffsetY;
//Cancels the event if it is cancelable.
e.PreventDefault();
}
}
}
- silverlight右键菜单实现
- Silverlight禁止右键菜单
- Silverlight右键菜单
- silverlight 右键菜单类
- Silverlight 4的是鼠标右键菜单的实现(一)
- Silverlight 4的是鼠标右键菜单的实现(二)
- Silverlight 4的是鼠标右键菜单的实现(三)
- Silverlight系列(右键菜单、控件移动的实现)
- hmtl实现右键菜单
- 实现右键菜单
- js实现右键菜单
- JS 实现右键菜单
- opengl 实现右键菜单
- Extjs实现右键菜单
- jqgrid右键菜单实现
- Ext4右键菜单实现
- jqgrid 右键菜单实现
- 实现右键菜单功能
- ldap增删改查
- convert tablespace的限制
- Android Notification消息提示
- X11不是threadsafe
- mina2 的例子
- silverlight右键菜单实现
- 【温故知新C/C++/opencv】取址符&||cv::groupRectangles||引用与值传递
- 求助~~~
- JIURL玩玩Win2k内存篇 分页机制
- [Java] URL
- 今天开始,记录点滴成长
- 惠普中国CEO孙振耀退休感言,男孩看了不用沉默,女孩看了不用哭
- 在线电子书
- GetCheckedRadioButton用法