locked
binding validation error in a piechart RRS feed

  • Question

  • using the toolkit PieSeries and running a debug.

    i see this message in the output window:

    System.Windows.Data Error: BindingExpression path error: 'ActualLegendItemStyle' property not found on 'System.Windows.Controls.DataVisualization.Charting.PieSeries' 'System.Windows.Controls.DataVisualization.Charting.PieSeries' (HashCode=24163637). BindingExpression: Path='ActualLegendItemStyle' DataItem='System.Windows.Controls.DataVisualization.Charting.PieSeries' (HashCode=24163637); target element is 'System.Windows.Controls.DataVisualization.Charting.LegendItem' (Name=''); target property is 'Style' (type 'System.Windows.Style')..

     i see this without changing anything (style/template), only by writing the simplest chart.

    any idea?

    Wednesday, December 30, 2009 5:55 AM

Answers

  • Hi shemesh,

    Yes, I reproduced the issue. After I analyzed the source code of PieSeries using reflector, I find the problem:

    PieSeries inherits directly from DataPointSeries. In the DataPointSeries, there's a CreateLegendItem method which uses Binding to populate legend item style for each legend item, the code is like this:
            LegendItem <>g__initLocal18 = new LegendItem();
            <>g__initLocal18.Owner = owner;
            LegendItem legendItem = <>g__initLocal18;
            Binding <>g__initLocal19 = new Binding("ActualLegendItemStyle");
            <>g__initLocal19.Source = this;
            legendItem.SetBinding(FrameworkElement.StyleProperty, <>g__initLocal19);

    However, neither PieSeries nor DataPointSeries defines the ActualLegendItemStyle property, this causes the error message you mentioned.

    I did more research on the issue and find that all the other series inherit directly or indirectly from DataPointSingleSeriesWithAxes which defines the ActualLegendItemStyle.
    So I suggest you to report a bug on codeplex, meanwhile, if you want to remove the error message, you can write a class which inherits from PieSeries and defines a ActualLegendItemStyle property like this:

     

    protected static readonly DependencyProperty ActualLegendItemStyleProperty = DependencyProperty.Register("ActualLegendItemStyle", typeof(Style), typeof(DataPointSeries), null);
    protected Style ActualLegendItemStyle
    {
        get
        {
            return (base.GetValue(ActualLegendItemStyleProperty) as Style);
        }
        set
        {
            base.SetValue(ActualLegendItemStyleProperty, value);
        }
    }
     Then you can use your own class instead of PieSeries. I hope this can help
    Monday, January 4, 2010 9:45 PM

All replies

  • maybe a ToolKit developer should take a look at this.

    anyone?

    Thursday, December 31, 2009 5:45 AM
  • Hi shemesh,

    It seems that there's something wrong in the binding, I would suggest you to watch the video to get an idea on how to draw a Pie chart first.

    And could you please tell which version of silverlight toolkit you use and share your code? It can help to figure out the problem.

    Thanks.

    Friday, January 1, 2010 1:26 AM
  • using version Nov 2009 (change set 35261).

    i have reproduced it with the simplest code:

     

    <Grid x:Name="LayoutRoot">
        <Grid Width="300" Height="300" HorizontalAlignment="Center" VerticalAlignment="Center">
            <chartingToolkit:Chart>
                <chartingToolkit:Chart.Series>
                    <chartingToolkit:PieSeries>
                        <chartingToolkit:PieSeries.ItemsSource>
                            <controls:ObjectCollection>
                                <sys:Double>1</sys:Double>
                                <sys:Double>2.3</sys:Double>
                                <sys:Double>3.5</sys:Double>
                                <sys:Double>5</sys:Double>
                            </controls:ObjectCollection>
                        </chartingToolkit:PieSeries.ItemsSource>
                    </chartingToolkit:PieSeries>
                </chartingToolkit:Chart.Series>
            </chartingToolkit:Chart>
        </Grid>
    </Grid>

     then run Debug and watch the output window.

    Sunday, January 3, 2010 2:31 AM
  • Hi shemesh,

    Yes, I reproduced the issue. After I analyzed the source code of PieSeries using reflector, I find the problem:

    PieSeries inherits directly from DataPointSeries. In the DataPointSeries, there's a CreateLegendItem method which uses Binding to populate legend item style for each legend item, the code is like this:
            LegendItem <>g__initLocal18 = new LegendItem();
            <>g__initLocal18.Owner = owner;
            LegendItem legendItem = <>g__initLocal18;
            Binding <>g__initLocal19 = new Binding("ActualLegendItemStyle");
            <>g__initLocal19.Source = this;
            legendItem.SetBinding(FrameworkElement.StyleProperty, <>g__initLocal19);

    However, neither PieSeries nor DataPointSeries defines the ActualLegendItemStyle property, this causes the error message you mentioned.

    I did more research on the issue and find that all the other series inherit directly or indirectly from DataPointSingleSeriesWithAxes which defines the ActualLegendItemStyle.
    So I suggest you to report a bug on codeplex, meanwhile, if you want to remove the error message, you can write a class which inherits from PieSeries and defines a ActualLegendItemStyle property like this:

     

    protected static readonly DependencyProperty ActualLegendItemStyleProperty = DependencyProperty.Register("ActualLegendItemStyle", typeof(Style), typeof(DataPointSeries), null);
    protected Style ActualLegendItemStyle
    {
        get
        {
            return (base.GetValue(ActualLegendItemStyleProperty) as Style);
        }
        set
        {
            base.SetValue(ActualLegendItemStyleProperty, value);
        }
    }
     Then you can use your own class instead of PieSeries. I hope this can help
    Monday, January 4, 2010 9:45 PM