我已经定制了我的Toolkit饼图,但现在所有切片都是相同的颜色

时间:2011-01-17 17:24:05

标签: silverlight silverlight-4.0 silverlight-toolkit

我已经实现了一个资源字典,以便我可以在饼图上自定义我的工具提示。但现在该系列返回一个饼图,其中切片的颜色相同。在应用资源字典之前,如何让它像它一样? PieDataPoint.xaml是我复制到项目中用作资源字典的文件。

1 个答案:

答案 0 :(得分:1)

我能够解决我的问题。下面是我的资源字典。我不得不手动将颜色定义为靠近底部的样式。

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
>


<!--http://silverlight.codeplex.com/SourceControl/changeset/view/18791#507651-->
<ControlTemplate
        x:Key="MyPieDataPointTemplate"
        TargetType="charting:PieDataPoint">
    <Grid
            x:Name="Root"
            Opacity="0">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="CommonStates">
                <VisualStateGroup.Transitions>
                    <VisualTransition GeneratedDuration="0:0:0.1"/>
                </VisualStateGroup.Transitions>
                <VisualState x:Name="Normal"/>
                <VisualState x:Name="MouseOver">
                    <Storyboard>
                        <DoubleAnimation
                                Storyboard.TargetName="MouseOverHighlight"
                                Storyboard.TargetProperty="Opacity"
                                To="0.6"
                                Duration="0"/>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
            <VisualStateGroup x:Name="SelectionStates">
                <VisualStateGroup.Transitions>
                    <VisualTransition GeneratedDuration="0:0:0.1"/>
                </VisualStateGroup.Transitions>
                <VisualState x:Name="Unselected"/>
                <VisualState x:Name="Selected">
                    <Storyboard>
                        <DoubleAnimation
                                Storyboard.TargetName="SelectionHighlight"
                                Storyboard.TargetProperty="Opacity"
                                To="0.6"
                                Duration="0"/>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
            <VisualStateGroup x:Name="RevealStates">
                <VisualStateGroup.Transitions>
                    <VisualTransition GeneratedDuration="0:0:0.5"/>
                </VisualStateGroup.Transitions>
                <VisualState x:Name="Shown">
                    <Storyboard>
                        <DoubleAnimation
                                Storyboard.TargetName="Root"
                                Storyboard.TargetProperty="Opacity"
                                To="1"
                                Duration="0"/>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Hidden">
                    <Storyboard>
                        <DoubleAnimation
                                Storyboard.TargetName="Root"
                                Storyboard.TargetProperty="Opacity"
                                To="0"
                                Duration="0"/>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Path
                x:Name="Slice"
                Data="{TemplateBinding Geometry}"
                Fill="{TemplateBinding Background}"
                Stroke="{TemplateBinding BorderBrush}"
                StrokeMiterLimit="1">
            <ToolTipService.ToolTip>
                <StackPanel>
                    <ContentControl
                            Content="{TemplateBinding FormattedIndependentValue}"
                            FontWeight="Bold"/>
                    <ContentControl
                            Content="{TemplateBinding FormattedDependentValue}"/>
                    <ContentControl
                            Content="{TemplateBinding FormattedRatio}"/>
                </StackPanel>
            </ToolTipService.ToolTip>
        </Path>
        <Path
                x:Name="SelectionHighlight"
                Data="{TemplateBinding GeometrySelection}"
                Fill="Red"
                StrokeMiterLimit="1"
                IsHitTestVisible="False"
                Opacity="0"/>
        <Path
                x:Name="MouseOverHighlight"
                Data="{TemplateBinding GeometryHighlight}"
                Fill="White"
                StrokeMiterLimit="1"
                IsHitTestVisible="False"
                Opacity="0"/>
    </Grid>
</ControlTemplate>

<!--http://silverlight.codeplex.com/SourceControl/changeset/view/18791#507636-->
<datavis:ResourceDictionaryCollection x:Key="MyPalette">
    <!-- Blue -->
    <ResourceDictionary>
        <RadialGradientBrush x:Key="Background" GradientOrigin="-0.1,-0.1" Center="0.075,0.015" RadiusX="1.05" RadiusY="0.9">
            <GradientStop Color="#FFB9D6F7"/>
            <GradientStop Color="#FF284B70" Offset="1"/>
        </RadialGradientBrush>
        <Style x:Key="DataPointStyle" TargetType="Control">
            <Setter Property="Template" Value="{StaticResource MyPieDataPointTemplate}"/>
            <Setter Property="Background" Value="{StaticResource Background}"/>
        </Style>
    </ResourceDictionary>
    <!-- Red -->
    <ResourceDictionary>
        <RadialGradientBrush x:Key="Background" GradientOrigin="-0.1,-0.1" Center="0.075,0.015" RadiusX="1.05" RadiusY="0.9">
            <GradientStop Color="#FFFBB7B5"/>
            <GradientStop Color="#FF702828" Offset="1"/>
        </RadialGradientBrush>
        <Style x:Key="DataPointStyle" TargetType="Control">
            <Setter Property="Template" Value="{StaticResource MyPieDataPointTemplate}"/>
            <Setter Property="Background" Value="{StaticResource Background}"/>
        </Style>
    </ResourceDictionary>
    <!-- Light Green -->
    <ResourceDictionary>
        <RadialGradientBrush x:Key="Background" GradientOrigin="-0.1,-0.1" Center="0.075,0.015" RadiusX="1.05" RadiusY="0.9">
            <GradientStop Color="#FFB8C0AC"/>
            <GradientStop Color="#FF5F7143" Offset="1"/>
        </RadialGradientBrush>
        <Style x:Key="DataPointStyle" TargetType="Control">
            <Setter Property="Template" Value="{StaticResource MyPieDataPointTemplate}"/>
            <Setter Property="Background" Value="{StaticResource Background}"/>
        </Style>
    </ResourceDictionary>
    <!-- Yellow -->
    <ResourceDictionary>
        <RadialGradientBrush x:Key="Background" GradientOrigin="-0.1,-0.1" Center="0.075,0.015" RadiusX="1.05" RadiusY="0.9">
            <GradientStop Color="#FFFDE79C"/>
            <GradientStop Color="#FFF6BC0C" Offset="1"/>
        </RadialGradientBrush>
        <Style x:Key="DataPointStyle" TargetType="Control">
            <Setter Property="Template" Value="{StaticResource MyPieDataPointTemplate}"/>
            <Setter Property="Background" Value="{StaticResource Background}"/>
        </Style>
    </ResourceDictionary>
    <!-- Indigo -->
    <ResourceDictionary>
        <RadialGradientBrush x:Key="Background" GradientOrigin="-0.1,-0.1" Center="0.075,0.015" RadiusX="1.05" RadiusY="0.9">
            <GradientStop Color="#FFA9A3BD"/>
            <GradientStop Color="#FF382C6C" Offset="1"/>
        </RadialGradientBrush>
        <Style x:Key="DataPointStyle" TargetType="Control">
            <Setter Property="Template" Value="{StaticResource MyPieDataPointTemplate}"/>
            <Setter Property="Background" Value="{StaticResource Background}"/>
        </Style>
    </ResourceDictionary>
    <!-- Magenta -->
    <ResourceDictionary>
        <RadialGradientBrush x:Key="Background" GradientOrigin="-0.1,-0.1" Center="0.075,0.015" RadiusX="1.05" RadiusY="0.9">
            <GradientStop Color="#FFB1A1B1"/>
            <GradientStop Color="#FF50224F" Offset="1"/>
        </RadialGradientBrush>
        <Style x:Key="DataPointStyle" TargetType="Control">
            <Setter Property="Template" Value="{StaticResource MyPieDataPointTemplate}"/>
            <Setter Property="Background" Value="{StaticResource Background}"/>
        </Style>
    </ResourceDictionary>
    <!-- Dark Green -->
    <ResourceDictionary>
        <RadialGradientBrush x:Key="Background" GradientOrigin="-0.1,-0.1" Center="0.075,0.015" RadiusX="1.05" RadiusY="0.9">
            <GradientStop Color="#FF9DC2B3"/>
            <GradientStop Color="#FF1D7554" Offset="1"/>
        </RadialGradientBrush>
        <Style x:Key="DataPointStyle" TargetType="Control">
            <Setter Property="Template" Value="{StaticResource MyPieDataPointTemplate}"/>
            <Setter Property="Background" Value="{StaticResource Background}"/>
        </Style>
    </ResourceDictionary>
    <!-- Gray Shade -->
    <ResourceDictionary>
        <RadialGradientBrush x:Key="Background" GradientOrigin="-0.1,-0.1" Center="0.075,0.015" RadiusX="1.05" RadiusY="0.9">
            <GradientStop Color="#FFB5B5B5"/>
            <GradientStop Color="#FF4C4C4C" Offset="1"/>
        </RadialGradientBrush>
        <Style x:Key="DataPointStyle" TargetType="Control">
            <Setter Property="Template" Value="{StaticResource MyPieDataPointTemplate}"/>
            <Setter Property="Background" Value="{StaticResource Background}"/>
        </Style>
    </ResourceDictionary>
    <!-- Blue -->
    <ResourceDictionary>
        <RadialGradientBrush x:Key="Background" GradientOrigin="-0.1,-0.1" Center="0.075,0.015" RadiusX="1.05" RadiusY="0.9">
            <GradientStop Color="#FF98C1DC"/>
            <GradientStop Color="#FF0271AE" Offset="1"/>
        </RadialGradientBrush>
        <Style x:Key="DataPointStyle" TargetType="Control">
            <Setter Property="Template" Value="{StaticResource MyPieDataPointTemplate}"/>
            <Setter Property="Background" Value="{StaticResource Background}"/>
        </Style>
    </ResourceDictionary>
    <!-- Brown -->
    <ResourceDictionary>
        <RadialGradientBrush x:Key="Background" GradientOrigin="-0.1,-0.1" Center="0.075,0.015" RadiusX="1.05" RadiusY="0.9">
            <GradientStop Color="#FFC1C0AE"/>
            <GradientStop Color="#FF706E41" Offset="1"/>
        </RadialGradientBrush>
        <Style x:Key="DataPointStyle" TargetType="Control">
            <Setter Property="Template" Value="{StaticResource MyPieDataPointTemplate}"/>
            <Setter Property="Background" Value="{StaticResource Background}"/>
        </Style>
    </ResourceDictionary>
    <!-- Cyan -->
    <ResourceDictionary>
        <RadialGradientBrush x:Key="Background" GradientOrigin="-0.1,-0.1" Center="0.075,0.015" RadiusX="1.05" RadiusY="0.9">
            <GradientStop Color="#FFADBDC0"/>
            <GradientStop Color="#FF446A73" Offset="1"/>
        </RadialGradientBrush>
        <Style x:Key="DataPointStyle" TargetType="Control">
            <Setter Property="Template" Value="{StaticResource MyPieDataPointTemplate}"/>
            <Setter Property="Background" Value="{StaticResource Background}"/>
        </Style>
    </ResourceDictionary>
    <!-- Special Blue -->
    <ResourceDictionary>
        <RadialGradientBrush x:Key="Background" GradientOrigin="-0.1,-0.1" Center="0.075,0.015" RadiusX="1.05" RadiusY="0.9">
            <GradientStop Color="#FF2F8CE2"/>
            <GradientStop Color="#FF0C3E69" Offset="1"/>
        </RadialGradientBrush>
        <Style x:Key="DataPointStyle" TargetType="Control">
            <Setter Property="Template" Value="{StaticResource MyPieDataPointTemplate}"/>
            <Setter Property="Background" Value="{StaticResource Background}"/>
        </Style>
    </ResourceDictionary>
    <!-- Gray Shade 2 -->
    <ResourceDictionary>
        <RadialGradientBrush x:Key="Background" GradientOrigin="-0.1,-0.1" Center="0.075,0.015" RadiusX="1.05" RadiusY="0.9">
            <GradientStop Color="#FFDCDCDC"/>
            <GradientStop Color="#FF757575" Offset="1"/>
        </RadialGradientBrush>
        <Style x:Key="DataPointStyle" TargetType="Control">
            <Setter Property="Template" Value="{StaticResource MyPieDataPointTemplate}"/>
            <Setter Property="Background" Value="{StaticResource Background}"/>
        </Style>
    </ResourceDictionary>
    <!-- Gray Shade 3 -->
    <ResourceDictionary>
        <RadialGradientBrush x:Key="Background" GradientOrigin="-0.1,-0.1" Center="0.075,0.015" RadiusX="1.05" RadiusY="0.9">
            <GradientStop Color="#FFF4F4F4"/>
            <GradientStop Color="#FFB7B7B7" Offset="1"/>
        </RadialGradientBrush>
        <Style x:Key="DataPointStyle" TargetType="Control">
            <Setter Property="Template" Value="{StaticResource MyPieDataPointTemplate}"/>
            <Setter Property="Background" Value="{StaticResource Background}"/>
        </Style>
    </ResourceDictionary>
    <!-- Gray Shade 4 -->
    <ResourceDictionary>
        <RadialGradientBrush x:Key="Background" GradientOrigin="-0.1,-0.1" Center="0.075,0.015" RadiusX="1.05" RadiusY="0.9">
            <GradientStop Color="#FFF4F4F4"/>
            <GradientStop Color="#FFA3A3A3" Offset="1"/>
        </RadialGradientBrush>
        <Style x:Key="DataPointStyle" TargetType="Control">
            <Setter Property="Template" Value="{StaticResource MyPieDataPointTemplate}"/>
            <Setter Property="Background" Value="{StaticResource Background}"/>
        </Style>
    </ResourceDictionary>
</datavis:ResourceDictionaryCollection>