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

 

第三种方法,还是使用微软的Menu构造函数,不过是在xaml界面中通过样式来使用它。不过笔者只在ArcGIS的中图形样式中使用成功了。其它的地方没有尝试,不过在SuperMap的feature应用理论上是可以成功。

菜单

   

Xaml页面

<UserControl x:Class="TDWS.Client.UI.SuperMapUI.RegionContextMenu"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    >

    <Grid x:Name="LayoutRoot">

        <Ellipse x:Name="ellHot" Height="10" Width="10" Fill="Green" Opacity="0"></Ellipse>

    </Grid>

</UserControl>

Xaml页面CS文件

 

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 TDWS.Client.UI.Query;

using Chaos.Controls.Windows;

using TDWS.Client.UI.Edit;

 

namespace TDWS.Client.UI.SuperMapUI

{

    public partial class RegionContextMenu : UserControl

    {

        public RegionContextMenu()

        {

            InitializeComponent();

            OnPropertyChanged(this,new DependencyPropertyChangedEventArgs() { });

        }

 

        IDictionary<string,object> _ContextDataSource = null;

       

        public static DependencyProperty _MenuDataSourceProperty = DependencyProperty.Register("ContextDataSource",

         typeof(IDictionary<string,object>),

         typeof(RegionContextMenu),

         new PropertyMetadata(new PropertyChangedCallback(OnPropertyChanged)));

   

   

        public IDictionary<string,object> ContextDataSource

        {

            get { return _ContextDataSource; }

            set { _ContextDataSource = value; }

        }

 

        private static void OnPropertyChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)

        {

            if (e.NewValue != null)

            {

                RegionContextMenu dd = new RegionContextMenu();

                d = dd;

                dd.ContextDataSource = e.NewValue as IDictionary<string,object>;

                dd.BindContextMenu();

               

            }

        }

 

        private void BindContextMenu()

        {

            ContextMenu menu = new ContextMenu();

 

            MenuItem regioninfo = new MenuItem();

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

            regioninfo.Click += new RoutedEventHandler(regioninfo_Click);

            menu.Items.Add(regioninfo);

 

            ContextMenuService.SetContextMenu(ellHot,menu);

        }

      

        //人口基本信息

        void regioninfo_Click(object sender,RoutedEventArgs e)

        {

            if (this.ContextDataSource.ContainsKey("Adcd"))

            {

                RegionBaseinformationUI baseInfo = new RegionBaseinformationUI(this.ContextDataSource["Adcd"].ToString());

                WindosEx.ShowDialog("人口基本信息",700,500,baseInfo);

            }

        }

    }

}

该右键菜单的使用,它是作为一种样式传该

 

<!--站点右键菜单样式-->

    <esri:MarkerSymbol x:Key="SiteContextMenuSymbol" OffsetX="10" OffsetY="10">

        <esri:MarkerSymbol.ControlTemplate>

            <ControlTemplate>

                <my:RegionContextMenu ContextDataSource="{Binding Attributes}"></my:RegionContextMenu>

            </ControlTemplate>

        </esri:MarkerSymbol.ControlTemplate>

    </esri:MarkerSymbol>

<esri:SimpleRenderer x:Key="SiteContextMenuRenderer" Symbol="{StaticResource SiteContextMenuSymbol}"></esri:SimpleRenderer>

相关文章

如何在Silverlight4(XAML)中绑定IsEnabled属性?我试过简单的...
我正在编写我的第一个vb.net应用程序(但我也会在这里标记c#,...
ProcessFile()是在UIThread上运行还是在单独的线程上运行.如...
我从同行那里听说,对sharepoint的了解对职业生涯有益.我们不...
我正在尝试保存一个类我的类对象的集合.我收到一个错误说明:...
我需要根据Silverlight中的某些配置值设置给定控件的Style.我...