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>
Ⅰ菜单类
①
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>
相关文章推荐
- ArcGIS API for Silverlight开发中鼠标左键点击地图上的点弹出窗口及右键点击弹出快捷菜单的实现代码
- Silverlight 4的是鼠标右键菜单的实现(一)
- Silverlight 4的是鼠标右键菜单的实现(二)
- Extjs实现菜单下拉和鼠标右键菜单(加入系统菜单权限判断,有权限则显示,无反之)
- C#实现Silverlight中右键菜单
- Extjs实现菜单下拉和鼠标右键菜单(加入系统菜单权限判断,有权限则显示,无反之)
- jQuery实现漂亮的指定区域内鼠标右键关联菜单可自定义图标
- C#中用鼠标右键选中tabpage选项卡 并且弹出右键菜单,实现选项卡的关闭
- 使用Javascript封装实现屏蔽鼠标右键系统键菜单,并绑定自定义的事件
- contextmenu用法-实现鼠标右键点击菜单功能
- Oracle ADF 菜单中鼠标右键实现新增和删除按纽
- Silverlight 4.0添加鼠标右键菜单和Silverlight全屏模式的进入退出
- Javascript实现鼠标右键特色菜单
- Silverlight实用窍门系列:4.Silverlight 4.0添加鼠标右键菜单和Silverlight全屏模式的进入退出。【附带源码实例】
- js屏蔽鼠标右键默认事件以实现自定义菜单
- 鼠标右键弹出快捷菜单的实现
- 我的YUV播放器MFC小笔记:右键菜单事件和非标题实现鼠标拖动
- flex 鼠标右键事件 和右键菜单的实现
- 4.Silverlight 4.0添加鼠标右键菜单和Silverlight全屏模式的进入退出。
- silverlight实现多级右键菜单