0

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

xml:

<!-- 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;                                                                     

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

4

1 回答 1

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"/>   ...
于 2013-03-20T17:35:01.207 回答