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