C# Silverlight数据可视化饼图-切片选择颜色更改

C# Silverlight数据可视化饼图-切片选择颜色更改,c#,wpf,silverlight,charts,windows-phone,C#,Wpf,Silverlight,Charts,Windows Phone,我正在开发Windows Phone 8应用程序 我有饼图的工作模型: 以下是单击前的屏幕截图: 以下是单击蓝色切片后的屏幕截图: 我在这里有一个问题,当我选择饼片时,片的颜色正在改变,但我不想改变片的颜色。我怎样才能做到这一点 我试着用blend来改变这种情况,但它没有告诉我状态 这是我的密码: <charting:Chart Height="400" Style="{StaticResource PhoneChartS

我正在开发Windows Phone 8应用程序

我有饼图的工作模型:

以下是单击前的屏幕截图:

以下是单击蓝色切片后的屏幕截图:

我在这里有一个问题,当我选择饼片时,片的颜色正在改变,但我不想改变片的颜色。我怎样才能做到这一点

我试着用blend来改变这种情况,但它没有告诉我状态

这是我的密码:

<charting:Chart
                Height="400"
                Style="{StaticResource PhoneChartStyle}"
                Template="{StaticResource PhoneChartPortraitTemplate}"
                x:Name="MyPieSeriesChart">
                <!-- Series -->
                <charting:PieSeries
                    Tap="PieSeries_Tap"
                    DoubleTap="PieSeries_DoubleTap"
                    IsSelectionEnabled="True"
                    ItemsSource="{StaticResource Activities}"
                    DependentValuePath="Count"
                    IndependentValuePath="Activity">
                    <charting:PieSeries.LegendItemStyle>
                        <Style TargetType="charting:LegendItem">
                            <Setter Property="Margin" Value="5 0 15 0"/>
                            <Setter Property="Foreground" Value="White"/>
                        </Style>
                    </charting:PieSeries.LegendItemStyle>
                </charting:PieSeries>
            </charting:Chart>

PhoneChartStyle和PhoneChartTemplate代码

<ControlTemplate x:Key="PhoneChartPortraitTemplate" TargetType="charting:Chart">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <datavis:Title
                Content="{TemplateBinding Title}"
                Style="{TemplateBinding TitleStyle}"/>
            <datavis:Legend x:Name="Legend"
                Grid.Row="2"
                Header="{TemplateBinding LegendTitle}"
                Style="{TemplateBinding LegendStyle}">
                <datavis:Legend.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal"/>
                    </ItemsPanelTemplate>
                </datavis:Legend.ItemsPanel>
                <datavis:Legend.Template>
                    <ControlTemplate TargetType="datavis:Legend">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <ScrollViewer
                                    Grid.Row="1"
                                    HorizontalScrollBarVisibility="Auto"
                                    VerticalScrollBarVisibility="Disabled"
                                    BorderThickness="0"
                                    Padding="0"
                                    IsTabStop="False">
                                <ItemsPresenter
                                        x:Name="Items"
                                        Margin="10,0,10,10"/>
                            </ScrollViewer>
                        </Grid>
                    </ControlTemplate>
                </datavis:Legend.Template>
            </datavis:Legend>
            <chartingprimitives:EdgePanel
                Grid.Column="0"
                Grid.Row="1"
                x:Name="ChartArea"
                Style="{TemplateBinding ChartAreaStyle}">
                <Grid
                    Canvas.ZIndex="-1"
                    Style="{TemplateBinding PlotAreaStyle}" />
            </chartingprimitives:EdgePanel>
        </Grid>
    </ControlTemplate>

    <!-- Chart Style for Phone -->
    <Style x:Key="PhoneChartStyle" TargetType="charting:Chart">
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Padding" Value="10" />
        <Setter Property="Palette">
            <Setter.Value>
                <datavis:ResourceDictionaryCollection>
                    <!-- Blue -->
                    <ResourceDictionary>
                        <SolidColorBrush x:Key="Background" Color="#E85F3D"/>
                        <Style x:Key="DataPointStyle" TargetType="Control">
                            <Setter Property="Background" Value="{StaticResource Background}" />
                        </Style>
                        <Style x:Key="DataShapeStyle" TargetType="Shape">
                            <Setter Property="Stroke" Value="{StaticResource Background}" />
                            <Setter Property="StrokeThickness" Value="2" />
                            <Setter Property="StrokeMiterLimit" Value="1" />
                            <Setter Property="Fill" Value="{StaticResource Background}" />
                        </Style>
                    </ResourceDictionary>
                    <!-- Red -->
                    <ResourceDictionary>
                        <SolidColorBrush x:Key="Background" Color="#76D164"/>
                        <Style x:Key="DataPointStyle" TargetType="Control">
                            <Setter Property="Background" Value="{StaticResource Background}" />
                        </Style>
                        <Style x:Key="DataShapeStyle" TargetType="Shape">
                            <Setter Property="Stroke" Value="{StaticResource Background}" />
                            <Setter Property="StrokeThickness" Value="2" />
                            <Setter Property="StrokeMiterLimit" Value="1" />
                            <Setter Property="Fill" Value="{StaticResource Background}" />
                        </Style>
                    </ResourceDictionary>
                    <!-- Light Green -->
                    <ResourceDictionary>
                        <SolidColorBrush x:Key="Background" Color="#648ED1"/>
                        <Style x:Key="DataPointStyle" TargetType="Control">
                            <Setter Property="Background" Value="{StaticResource Background}" />
                        </Style>
                        <Style x:Key="DataShapeStyle" TargetType="Shape">
                            <Setter Property="Stroke" Value="{StaticResource Background}" />
                            <Setter Property="StrokeThickness" Value="2" />
                            <Setter Property="StrokeMiterLimit" Value="1" />
                            <Setter Property="Fill" Value="{StaticResource Background}" />
                        </Style>
                    </ResourceDictionary>
                </datavis:ResourceDictionaryCollection>
            </Setter.Value>
        </Setter>
        <Setter Property="LegendStyle">
            <Setter.Value>
                <Style TargetType="datavis:Legend">
                    <Setter Property="HorizontalAlignment" Value="Center"/>
                    <Setter Property="VerticalAlignment" Value="Center"/>
                    <Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/>
                    <Setter Property="Margin" Value="20"/>
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="ChartAreaStyle">
            <Setter.Value>
                <Style TargetType="Panel">
                    <Setter Property="MinWidth" Value="100" />
                    <Setter Property="MinHeight" Value="75" />
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="PlotAreaStyle">
            <Setter.Value>
                <Style TargetType="Grid">
                    <Setter Property="Background" Value="Transparent"/>
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="Template" Value="{StaticResource PhoneChartPortraitTemplate}"/>
    </Style>

您应该编辑您的
数据点样式
(在Visual Studio中右键单击->
编辑其他模板->编辑数据点样式->编辑副本
),在下面找到此代码,并从所选的
状态中删除
情节提要

<VisualStateGroup x:Name="SelectionStates">
    <VisualStateGroup.Transitions>
        <VisualTransition GeneratedDuration="0:0:0.1"/>
    </VisualStateGroup.Transitions>
    <VisualState x:Name="Unselected"/>
    <VisualState x:Name="Selected">
        <!-- This storyboard should be removed -->
        <!--<Storyboard>
            <DoubleAnimation
                Storyboard.TargetName="SelectionHighlight"
                Storyboard.TargetProperty="Opacity"
                To="0.6"
                Duration="0"/>
        </Storyboard>-->
    </VisualState>
</VisualStateGroup>
<Style x:Name="NewDataPointStyle" TargetType="charting:PieDataPoint">
<Setter Property="Palette">
<Setter.Value>
<datavis:ResourceDictionaryCollection>
    <!-- Blue -->
    <ResourceDictionary>
        <SolidColorBrush x:Key="Background" Color="#E85F3D"/>
        <Style x:Key="DataPointStyle" TargetType="charting:PieDataPoint" BasedOn="{StaticResource NewDataPointStyle}">
            <Setter Property="Background" Value="{StaticResource Background}" />
        </Style>
    ...