Howto: 使用templates修改legend控件的颜色和字体

文章编号 : 38761
软件: ArcGIS API for Microsoft Silverlight/WPF 10
操作系统: N/A
已邀请:

EsriSupport

赞同来自:

摘要: Legend控件是在ArcGIS API for Microsoft Silverlight/WPF 2.1新增的控件,在ESRI.ArcGIS.Client.Toolkit动态库下。Legend控件显示了地图中图层和符号的内容。
Legend控件可以通过修改template进行客户化,包括颜色和字体。

内容:
下面的步骤演示了怎样修改颜色和字体。
1 Code in Xaml: <UserControl x:Class="ArcGISSilverlightSDK.MainPage"
xmlns="http://schemas.microsoft.com/w ... ot%3B
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esri="http://schemas.esri.com/arcgis ... gt%3B
<Grid x:Name="LayoutRoot" >

<esri:Map x:Name="MyMap" Extent="-15000000,2000000,-7000000,8000000">
<esri:ArcGISTiledMapServiceLayer ID="Street Map"
Url="http://services.arcgisonline.c ... gt%3B
<esri:ArcGISDynamicMapServiceLayer ID="United States" Opacity="0.6"
Url="http://sampleserver1.arcgisonl ... gt%3B
<esri:FeatureLayer ID="Points of Interest"
Url="http://sampleserver3.arcgisonl ... ot%3B />
</esri:Map>

<Border Background="#77919191" BorderThickness="1" CornerRadius="5"
HorizontalAlignment="Right" VerticalAlignment="Top"
Margin="20" Padding="5" BorderBrush="Black" >

<!--Legend control-->
<esri:Legend Map="{Binding ElementName=MyMap}"
LayerIDs="Points of Interest,United States"
LayerItemsMode="Tree"
Background="Black">

<!--Style of layer-->
<esri:Legend.MapLayerTemplate>
<DataTemplate>
<ContentControl Content="{Binding Label}"
FontFamily="Times New Roman"
FontWeight="Bold"
FontSize="20"
Foreground="Red">
</ContentControl>
</DataTemplate>
</esri:Legend.MapLayerTemplate>

<!--Style of sub layer-->
<esri:Legend.LayerTemplate>
<DataTemplate>
<ContentControl Content="{Binding Label}"
FontFamily="Verdana"
FontWeight="Bold"
FontSize="16"
Foreground="Yellow">
</ContentControl>
</DataTemplate>
</esri:Legend.LayerTemplate>

<!--Style of legend item-->
<esri:Legend.LegendItemTemplate >
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding ImageSource}"></Image>
<ContentControl Content="{Binding Label}"
FontFamily="Arial Black"
FontSize="12"
FontStyle="Italic"
Foreground="White">
</ContentControl>
</StackPanel>
</DataTemplate>
</esri:Legend.LegendItemTemplate>
</esri:Legend>

</Border>
</Grid>
</UserControl>

Code behind C#:

using System.Windows.Controls;
namespace ArcGISSilverlightSDK
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
}
}
2 结果








创建时间:2011-03-18
最近更新: 2011-04-01


原文链接
http://support.esrichina.com.c ... .html

要回复问题请先登录注册