arcgis for silverlight 中修改DataTemplate解决思路
来源:互联网 发布:银联数据待遇 编辑:程序博客网 时间:2024/04/30 11:36
最近又开始捣鼓silverlight,其中一个问题是修改DataTemplate,控件中的值,用一下方法虽然可以获取值,但是无法修改值:
System.Windows.DataTemplate dt2 = LayoutRoot.Resources["MyFeatureLayerInfoWindowTemplate"] as System.Windows.DataTemplate;
StackPanel panel2 = (StackPanel)dt2.LoadContent();
TextBlock tbCategory2 = panel2.FindName("text1") as TextBlock;
因此改变了思路,就是动态添加DataTemplate,首先创建DataTemplate,然后动态绑定到控件,这样就是先修改值,在绑定的思路,例子如下:
<UserControl x:Class="SilverlightApplication2.MainPage"
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"
xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot">
<Grid.Resources>
<esri:SimpleRenderer x:Key="MySimpleRenderer">
<esri:SimpleRenderer.Symbol>
<esri:SimpleFillSymbol Fill="#01FFFFFF" BorderBrush="#88000000" BorderThickness="2" />
</esri:SimpleRenderer.Symbol>
</esri:SimpleRenderer>
<DataTemplate x:Key="LocationInfoWindowTemplate">
<StackPanel Margin="2">
<TextBlock Text="Location:" />
<TextBlock Text="{Binding X, StringFormat=X\=\{0:0.000\}}" />
<TextBlock Text="{Binding Y, StringFormat=Y\=\{0:0.000\}}" />
<TextBlock x:Name="text2" Text="111"></TextBlock>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="MyFeatureLayerInfoWindowTemplate" x:Name="DataTemplate1">
<StackPanel Margin="2">
<TextBlock Text="{Binding [STATE_NAME]}" Foreground="Black" FontSize="12" />
<TextBlock x:Name="text1" Text="111"></TextBlock>
</StackPanel>
</DataTemplate>
</Grid.Resources>
<esri:Map x:Name="MyMap" WrapAround="True" Extent="-15000000,2000000,-7000000,8000000" MouseClick="MyMap_MouseClick">
<esri:ArcGISTiledMapServiceLayer ID="Street Map"
Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
<esri:FeatureLayer ID="MyFeatureLayer"
Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5"
OutFields="STATE_NAME,POP2007"
Renderer="{StaticResource MySimpleRenderer}"
/>
</esri:Map>
<esri:InfoWindow x:Name="MyInfoWindow"
Padding="2"
CornerRadius="20"
Background="LightSalmon"
Map="{Binding ElementName=MyMap}"
MouseLeftButtonUp="MyInfoWindow_MouseLeftButtonUp" />
</Grid>
</UserControl>
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Toolkit;
using System.IO;
using System.Windows.Markup;
using System.Text;
namespace SilverlightApplication2
{
public partial class MainPage : UserControl
{
TextBlock tb1 = new TextBlock();
public MainPage()
{
InitializeComponent();
}
//动态创建模板
private DataTemplate ss()
{
string xaml = @"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
xmlns:local=""clr-namespace:GalaxyErp.Module"">
<StackPanel VerticalAlignment=""Stretch"" HorizontalAlignment=""Stretch"">
<TextBlock Text=""{Binding [STATE_NAME]}"" Foreground=""Black"" FontSize=""12"" />
<TextBlock x:Name=""text1"" Text=""4343""></TextBlock>
</StackPanel>
</DataTemplate>";
// Stream s = new MemoryStream(Encoding.UTF8.GetBytes(xaml));
return (DataTemplate)XamlReader.Load(xaml);
}
private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
{
FeatureLayer featureLayer = MyMap.Layers["MyFeatureLayer"] as FeatureLayer;
System.Windows.Point screenPnt = MyMap.MapToScreen(e.MapPoint);
// Account for difference between Map and application origin
GeneralTransform generalTransform = MyMap.TransformToVisual(Application.Current.RootVisual);
System.Windows.Point transformScreenPnt = generalTransform.Transform(screenPnt);
IEnumerable<Graphic> selected =
featureLayer.FindGraphicsInHostCoordinates(transformScreenPnt);
foreach (Graphic g in selected)
{
MyInfoWindow.Anchor = e.MapPoint;
MyInfoWindow.IsOpen = true;
MyInfoWindow.ContentTemplate = ss();//
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Toolkit;
using System.IO;
using System.Windows.Markup;
using System.Text;
namespace SilverlightApplication2
{
public partial class MainPage : UserControl
{
TextBlock tb1 = new TextBlock();
public MainPage()
{
InitializeComponent();
}
private DataTemplate ss()
{
string xaml = @"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
xmlns:local=""clr-namespace:GalaxyErp.Module"">
<StackPanel VerticalAlignment=""Stretch"" HorizontalAlignment=""Stretch"">
<TextBlock Text=""{Binding [STATE_NAME]}"" Foreground=""Black"" FontSize=""12"" />
<TextBlock x:Name=""text1"" Text=""4343""></TextBlock>
</StackPanel>
</DataTemplate>";
// Stream s = new MemoryStream(Encoding.UTF8.GetBytes(xaml));
return (DataTemplate)XamlReader.Load(xaml);
}
private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
{
FeatureLayer featureLayer = MyMap.Layers["MyFeatureLayer"] as FeatureLayer;
System.Windows.Point screenPnt = MyMap.MapToScreen(e.MapPoint);
// Account for difference between Map and application origin
GeneralTransform generalTransform = MyMap.TransformToVisual(Application.Current.RootVisual);
System.Windows.Point transformScreenPnt = generalTransform.Transform(screenPnt);
IEnumerable<Graphic> selected =
featureLayer.FindGraphicsInHostCoordinates(transformScreenPnt);
foreach (Graphic g in selected)
{
MyInfoWindow.Anchor = e.MapPoint;
MyInfoWindow.IsOpen = true;
MyInfoWindow.ContentTemplate = ss();//绑定模板
//Since a ContentTemplate is defined, Content will define the DataContext for the ContentTemplate
MyInfoWindow.Content = g.Attributes;
return;
}
InfoWindow window = new InfoWindow()
{
Anchor = e.MapPoint,
Map = MyMap,
IsOpen = true,
Placement=InfoWindow.PlacementMode.Auto,
ContentTemplate = LayoutRoot.Resources["LocationInfoWindowTemplate"] as System.Windows.DataTemplate,
//Since a ContentTemplate is defined, Content will define the DataContext for the ContentTemplate
Content = e.MapPoint
};
LayoutRoot.Children.Add(window);
}
private void MyInfoWindow_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
MyInfoWindow.IsOpen = false;
}
}
}
//Since a ContentTemplate is defined, Content will define the DataContext for the ContentTemplate
MyInfoWindow.Content = g.Attributes;
return;
}
InfoWindow window = new InfoWindow()
{
Anchor = e.MapPoint,
Map = MyMap,
IsOpen = true,
Placement=InfoWindow.PlacementMode.Auto,
ContentTemplate = LayoutRoot.Resources["LocationInfoWindowTemplate"] as System.Windows.DataTemplate,
//Since a ContentTemplate is defined, Content will define the DataContext for the ContentTemplate
Content = e.MapPoint
};
LayoutRoot.Children.Add(window);
}
private void MyInfoWindow_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
MyInfoWindow.IsOpen = false;
}
}
}
- arcgis for silverlight 中修改DataTemplate解决思路
- Silverlight.解决DataTemplate中绑定的Command无法触发的问题
- ArcGIS API for Silverlight 地图中解决点众多的簇解决方法
- Arcgis for silverlight 资料
- arcgis api for silverlight
- ArcGIS API for Silverlight 解决众多密集点分层显示
- ArcGIS For Silverlight API 开发中利用WebService调用ArcObjects
- ArcGIS API for Silverlight中通过https访问rest服务
- ArcGIS API for Silverlight开发中常用问题汇总
- ArcGIS API for Silverlight中加载Google地形图(瓦片图
- ArcGIS API for Silverlight代码中使用Template模板
- Silverlight中的DataTemplate
- Arcgis for silverlight的安装
- ArcGIS for SilverLight之FindGraphicsInHostCoordinates
- Silverlight for ArcGIS 经纬度定位
- ArcGIS API FOR Silverlight资源
- Arcgis for silverlight 坐标转换
- ArcGIS For Silverlight api 简介
- Android Bitmap资源的简单池化
- Elastic IP 和 Public IP 的区别
- c语言中相关标准
- 通过 Masonry使用纯代码方式编写 Auto Layout--配置 Masonry
- android WebView 和 HttpClient cookie同步
- arcgis for silverlight 中修改DataTemplate解决思路
- windows bat(批处理)——IF详解
- 【Cocos2d-x】从C++过渡到Lua
- easyui datagrid-detailview.js 子数据表显示BUG
- 整理CVPR2012的文章
- Android 自定义控件实现刮刮卡效果 真的就只是刮刮卡么
- 网卡设置查看工具
- Linux Bash脚本编程语言中的美学与哲学
- java语言中的final关键字