微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Silverlight 4的是鼠标右键菜单的实现(二)

前面一篇文章已经写了自己构建右键菜单方法,本章主要来探讨一下,使用微软Menu 类来构建右键菜单方法,这些用法笔者在自己的系统中都有所采用。

第二种实现方法,就是用微软的Menu类来构建 ,并且在相应的地方实例化该菜单,把它弹出来。

菜单

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;

using TDWS.Client.UI.Query;

using Chaos.Controls.Windows;

using TDWS.Client.UI.Edit;

using System.Collections.Generic;

using SuperMap.Web.Core;

 

namespace TDWS.Client.UI.SuperMapUI

{

    public class ReservoirRightMenu

    {

        public ContextMenu menu = new ContextMenu();

        public ReservoirRightMenu()

        {

                          MenuItem ReservoirInfo = new MenuItem();

            ReservoirInfo.Header = "人口基本信息";

            ReservoirInfo.Click += new RoutedEventHandler(ReservoirInfo_Click);

            menu.Items.Add(ReservoirInfo);

        }

        public ContextMenu ContextMenu()

        {

            MenuItem ReservoirInfo = new MenuItem();

            ReservoirInfo.Header = "人口基本信息";

            ReservoirInfo.Click += new RoutedEventHandler(ReservoirInfo_Click);

            menu.Items.Add(ReservoirInfo);

 

            return menu;

        }

        //人口基本信息

        void ReservoirInfo_Click(object sender,RoutedEventArgs e)

        {

               //实例化一个人口基本信息对话框。

                ReservoirBaseinformationUI reservoirInfo = new ReservoirBaseinformationUI();

//弹出对话框

                WindosEx.ShowDialog("人口基本信息",700,600,reservoirInfo);

          

        }

    }

}

 

 

菜单的实例化,弹出

/// <summary>

        ///行政区右键菜单¹

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        void featureRiver_MouseRightButtonDown(object sender,MouseButtonEventArgs e)

        {

            e.Handled = true;

        }

        /// <summary>

        ///行政区右键菜单¹¹

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        void featureRiver_MouseRightButtonUp(object sender,MouseButtonEventArgs e)

        {

            RiverRightMenu riverContextMenu = new RiverRightMenu();

            ContextMenu menu = riverContextMenu..Menu;

            menu.VerticalOffset = e.GetPosition(this).Y;

            menu.HorizontalOffset = e.GetPosition(this).X;

            menu.IsOpen = true;

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐