Problems with PieDataPoint template - all slices are colored in the same color

171 views Asked by At

I'm trying to redefine a template for a PieDataPoint so only IndependentValue and FormattedRatio are being shown in the ToolTipLabel. It works fine, but the whole chart is being colored in one color. Then I defined my own Palette, but it looks like being ignored. I know this theme has already being discussed here but the proposed solutions didn’t work for me. Maybe I miss something. Can someone help me? Yes, and I use WPF4 already.

Charting library:

  xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
  xmlns:datavis ="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"

Here is my XAML code:

<Window.Resources>
    <ControlTemplate x:Key="MyPieDataPointTemplate" TargetType="{x:Type 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 Duration="0" Storyboard.TargetName ="MouseOverHighlight" Storyboard.TargetProperty ="Opacity" To="0.6" />
                        </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 Duration="0" Storyboard.TargetName ="SelectionHighlight" Storyboard.TargetProperty ="Opacity" To="0.6" />
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>

                <VisualStateGroup x:Name="RevealStates">
                    <VisualStateGroup.Transitions>
                        <VisualTransition GeneratedDuration="0:0:0.5" />
                    </VisualStateGroup.Transitions>
                    <VisualState x:Name="Shown">
                        <Storyboard>
                            <DoubleAnimation Duration="0" Storyboard.TargetName ="Root" Storyboard.TargetProperty ="Opacity" To="1" />
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Hidden">
                        <Storyboard>
                            <DoubleAnimation Duration="0" Storyboard.TargetName ="Root" Storyboard.TargetProperty ="Opacity" To="0" />
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups >

            <Path x:Name="Slice" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" Data="{TemplateBinding Geometry}">
                <ToolTipService.ToolTip>
                    <StackPanel>
                        <ContentControl Content="{TemplateBinding IndependentValue}" />
                        <ContentControl Content="{TemplateBinding FormattedRatio}" />
                    </StackPanel>
                </ToolTipService.ToolTip>
            </Path>

            <Path x:Name="SelectionHighlight" IsHitTestVisible="False" Opacity="0" Fill="Red" Data="{TemplateBinding GeometrySelection}" />
            <Path x:Name="MouseOverHighlight" IsHitTestVisible="False" Opacity="0" Fill="White" Data="{TemplateBinding GeometryHighlight}" />
        </Grid>
    </ControlTemplate>

    <Style x:Key="PieDataPointStyle" TargetType="{x:Type charting:PieDataPoint}">
        <Setter Property="Template" Value="{StaticResource MyPieDataPointTemplate}"/>
    </Style>

    <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>
        </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>
        </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>
        </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>
        </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>
        </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>
        </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>
        </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>
        </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>
        </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>
        </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>
        </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>
        </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>
        </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>
        </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>
        </ResourceDictionary>
    </datavis:ResourceDictionaryCollection>
</Window.Resources>

<Grid Opacity="1">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Calendar Grid.Row="0" Grid.Column="0" Name="BSDECalender" DisplayMode="Year" Margin="15" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" DisplayModeChanged="BSDECalender_DisplayModeChanged"/>

    <charting:Chart x:Name="c_ProcessGroups" HorizontalAlignment="Stretch" Margin="15" MinHeight="600" MinWidth="800" Title="Produktiv / Unproduktiv" Grid.Column="1" Grid.Row="0">
        <charting:Chart.Series>
            <charting:PieSeries ItemsSource="{Binding}" DependentValuePath="Value" IndependentValuePath="Key" Title="" IsSelectionEnabled="True" DataPointStyle="{StaticResource PieDataPointStyle}" Palette="{StaticResource MyPalette}"/>
        </charting:Chart.Series>
    </charting:Chart>
0

There are 0 answers