ControlTemplates共享相同的颜色

时间:2013-03-19 23:03:55

标签: c# silverlight xaml arcgis

我正在尝试使用此控制模板作为资源来为多边形指定符号。用户在创建多边形时选择多边形的颜色。但是,当用户创建新的多边形并选择不同的颜色时,会切换到所有添加的多边形的最新颜色。

的Xaml:

<!-- Polygon -->
<esri:SimpleFillSymbol x:Key="KmlPolygonStyle">
    <esri:SimpleFillSymbol.ControlTemplate>
        <ControlTemplate x:Name="CustomKmlPolygonTemplate">
            <Grid>
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal">
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="Element"
                                                 Storyboard.TargetProperty="StrokeThickness"
                                                 To="1" Duration="0:0:0.1"/>
                                <DoubleAnimation Storyboard.TargetName="Element"
                                                 Storyboard.TargetProperty="Fill.Opacity"
                                                 To="0.5" Duration="0:0:0.1"/>
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="MouseOver">
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="Element"
                                                 Storyboard.TargetProperty="StrokeThickness"
                                                 To="2" Duration="0:0:0.1"/>
                                <DoubleAnimation Storyboard.TargetName="Element"
                                                 Storyboard.TargetProperty="Fill.Opacity"
                                                 To="0.7" Duration="0:0:0.1"/>
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Selected">
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="Element"
                                                 Storyboard.TargetProperty="StrokeThickness"
                                                 To="3" Duration="0:0:0.1"/>
                                <DoubleAnimation Storyboard.TargetName="Element"
                                                 Storyboard.TargetProperty="Fill.Opacity"
                                                 To="0.9" Duration="0:0:0.1"/>
                            </Storyboard>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
                <Path x:Name="Element"
                            Fill="{Binding Symbol.Fill}" Stroke="{Binding Symbol.BorderBrush}"
                            StrokeStartLineCap="Round" StrokeThickness="1" 
                            StrokeLineJoin="Round" StrokeEndLineCap="Round" />
            </Grid>
        </ControlTemplate>
    </esri:SimpleFillSymbol.ControlTemplate>
</esri:SimpleFillSymbol>

C#代码:

 var kmlSymbol = Application.Current.Resources["KmlPolygonStyle"] as SimpleFillSymbol;                                                             
 kmlSymbol.Fill = new SolidColorBrush(LayerColorPicker.SelectedColor.Color); 
 kmlSymbol.BorderBrush = new SolidColorBrush(LayerColorPicker.SelectedColor.Color);
 kmlSymbol.BorderThickness = 1;
 kmlSymbol.Fill.Opacity = 0.5;                                                                       
 kmlRenderer.Symbol = kmlSymbol;                                                                     

如何使每个添加的多边形使用适当的选定颜色。

1 个答案:

答案 0 :(得分:0)

通过将绑定更改为一次清除了问题。

              ...     <Path x:Name="Element"
                            Fill="{Binding Symbol.Fill, Mode=OneTime}" Stroke="{Binding Symbol.BorderBrush, Mode=OneTime}"
                            StrokeStartLineCap="Round" StrokeThickness="1" 
                            StrokeLineJoin="Round" StrokeEndLineCap="Round"/>   ...