Binding color for PieSeries items

3 posts, 0 answers
  1. m0rg0t
    m0rg0t avatar
    8 posts
    Member since:
    Feb 2011

    Posted 11 Mar 2013 Link to this post

    Hello.

    Is it possible to bind color from object property for PieSeries items (when using binding to to custom objects)?


    <chart:RadPieChart Width="350" Height="350" Name="AchievesChart">                                                   
        <chart:PieSeries x:Name="AchievesChartPieces"          
             ItemsSource="{Binding Path=Categories}"                      
            DataContext="{Binding Main, Source={StaticResource Locator}}" Loaded="AchievesChartPieces_Loaded">                               
            <chart:PieSeries.LabelDefinitions>
                <chart:ChartSeriesLabelDefinition Binding="ChartLabel"/>
            </chart:PieSeries.LabelDefinitions>
            <!--<chart:PieSeries.SliceStyles>
                <Style TargetType="Path">
                    <Setter Property="Fill" Value="Green"/>
                    <Setter Property="Stroke" Value="Black" />
                </Style>
            </chart:PieSeries.SliceStyles>-->
        </chart:PieSeries>
    </chart:RadPieChart>


  2. m0rg0t
    m0rg0t avatar
    8 posts
    Member since:
    Feb 2011

    Posted 12 Mar 2013 Link to this post

    For example if using something like: 

    Style testStyle = new Style();
    Setter testSetter = new Setter();
    testStyle.Setters.Add(testSetter);
    (sender as PieSeries).SliceStyles.Add(testStyle);

    What testStyle.TargetType should be set to get equal result like:

    <chart:PieSeries.SliceStyles>
        <Style TargetType="Path">
            <Setter Property="Fill" Value="Orange"/>
            <Setter Property="Stroke" Value="Black" />
        </Style>
     
        <Style TargetType="Path">
            <Setter Property="Fill" Value="Gray"/>
            <Setter Property="Stroke" Value="Black" />
        </Style>
     
        <Style TargetType="Path">
            <Setter Property="Fill" Value="Cyan"/>
            <Setter Property="Stroke" Value="Black" />
        </Style>
     
        <Style TargetType="Path">
            <Setter Property="Fill" Value="Purple"/>
            <Setter Property="Stroke" Value="Black" />
        </Style>
     
        <Style TargetType="Path">
            <Setter Property="Fill" Value="Green"/>
            <Setter Property="Stroke" Value="Black" />
        </Style>
    </chart:PieSeries.SliceStyles>

  3. DevCraft banner
  4. m0rg0t
    m0rg0t avatar
    8 posts
    Member since:
    Feb 2011

    Posted 12 Mar 2013 Link to this post

    Find solution

    Style testStyle = new Style();
    testStyle.TargetType = typeof(System.Windows.Shapes.Path);
    Setter testSetter = new Setter();
    testSetter.Property = System.Windows.Shapes.Path.FillProperty;                   
    testSetter.Value = project.Color.Replace("#","#FF").ToUpper();
    testStyle.Setters.Add(testSetter);
     
    testSetter = new Setter();
    testSetter.Property = System.Windows.Shapes.Path.StrokeProperty;
    testSetter.Value = "Black";
    testStyle.Setters.Add(testSetter);
     
    (sender as PieSeries).SliceStyles.Add(testStyle);
Back to Top