您的位置:首页 > 其它

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

2010-12-25 14:13 946 查看
第三种方法,还是使用微软的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("人口基本信息", 0, 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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐