silverlight   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了silverlight右键菜单实现大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

1.添加一个<TextBlock>到Page.xaml中 <UserControl x:Class="rightClick.Page"     xmlns="http://scheR_854_11845@as.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://scheR_854_11845@as.microsoft.com/winfx/2006/xaml"    

1.添加一个<TextBlock>到Page.xaml中


<UserControl x:Class="rightClick.Page"
    xmlns="http://scheR_854_11845@as.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://scheR_854_11845@as.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"  @H_675_34@(这一点是最关键的!!!!!)


        <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右键菜单实现所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。