首页 > 代码库 > ArcGIS API For Silverlight 中 用户自定义Symbol在C#中调用

ArcGIS API For Silverlight 中 用户自定义Symbol在C#中调用

ArcGIS API For Silverlight 中 用户自定义Symbol在C#中调用

1.创建帮助类,其中,Application.LoadComponent的参数/Tel.Jsyd.FileImport;component/Themes/Symbol.xaml,是自定义Symbol所在位置

public class SymbolHelper    {        static SymbolHelper()        {            ResourceDictionary rd = new ResourceDictionary();            Application.LoadComponent(rd, new Uri("/Tel.Jsyd.FileImport;component/Themes/Symbol.xaml", UriKind.Relative));            Application.Current.Resources.MergedDictionaries.Add(rd);        }        public static Symbol GetCommonSymbol(string key)        {            if (Application.Current.Resources.Contains(key))            {                object symbol = Application.Current.Resources[key];                return symbol as Symbol;            }            return null;        }}
View Code

 2.自定义Symbol

 <ResourceDictionary    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:esrisb="clr-namespace:ESRI.ArcGIS.Client.Symbols;assembly=ESRI.ArcGIS.Client">   <esrisb:FillSymbol x:Name="CurrentProjectSymbol" BorderBrush="Green" BorderThickness="2">        <esrisb:FillSymbol.Fill>            <SolidColorBrush Color="Green" Opacity="0" />        </esrisb:FillSymbol.Fill>    </esrisb:FillSymbol>    <esrisb:FillSymbol x:Key="CurrentProjectFlickingSymbol">        <esrisb:FillSymbol.ControlTemplate>            <ControlTemplate xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">                <Grid>                    <vsm:VisualStateManager.VisualStateGroups>                        <vsm:VisualStateGroup x:Name="CommonStates">                            <vsm:VisualState x:Name="MouseOver">                                <Storyboard>                                    <DoubleAnimation BeginTime="0" Storyboard.TargetName="Element" Storyboard.TargetProperty="(Shape.Opacity)" To="0.75" Duration="00:00:01" RepeatBehavior="Forever"/>                                </Storyboard>                            </vsm:VisualState>                            <vsm:VisualState x:Name="Normal">                                <Storyboard>                                    <DoubleAnimation BeginTime="0" Storyboard.TargetName="Element" Storyboard.TargetProperty="(Shape.Opacity)" To="0.75" Duration="00:00:02" RepeatBehavior="Forever"/>                                </Storyboard>                            </vsm:VisualState>                        </vsm:VisualStateGroup>                    </vsm:VisualStateManager.VisualStateGroups>                    <Path x:Name="Element" Fill="Green" Opacity="0.15" Stroke="Green" StrokeThickness="2"></Path>                </Grid>            </ControlTemplate>        </esrisb:FillSymbol.ControlTemplate>    </esrisb:FillSymbol></ResourceDictionary>
View Code

 3.C#中调用

if (this.isPlotCurrent)                this.Plot.Graphic.Symbol = SymbolHelper.GetCommonSymbol("CurrentProjectSymbol");
View Code

 

ArcGIS API For Silverlight 中 用户自定义Symbol在C#中调用