silverlight右键菜单实现

silverlight右键菜单实现,第1张

概述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"    

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" >
                 <img src="http://go.microsoft.com/fwlink/?linkID=108181" alt="Get Microsoft Silverlight" />
            </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右键菜单实现所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1078061.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存