Legend MarkerFill Color linked to series Color

3 posts, 0 answers
  1. Olivier Masset
    Olivier Masset avatar
    3 posts
    Member since:
    Oct 2009

    Posted 08 Nov 2011 Link to this post

    Hello,
    I'm working on a MVVM application.
    The user can dynamically change the RadChart series color with the interface.

    Code behind:
            ...
    Binding strokeBinding = new Binding(".")
    {
     Source = dataSerie,
     Mode = BindingMode.OneWay,
     Path = new PropertyPath("Color"),
     Converter = new ColorToBrushConverter()
    };

    BindingOperations.SetBinding(appearanceSettings, AppearanceSettings.StrokeProperty, strokeBinding);
            ...

    The legend is automatically generated but colors do not change automatically with the series color.
    I tried to turn auto genarated items to false and used a binding between the color and the legend MarkerFillProperty.
    It sets the marker with the right color but if I change dynamically the color it doesn't work.

    Code behind:
    ChartLegend.UseAutoGeneratedItems = false;

       ...

    ChartLegendItem chartLegendItem = new ChartLegendItem();
    chartLegendItem.Label = dataSerie.LegendLabel;

    Binding markerFillBinding = new Binding(".")
    {
     Source = dataSerie,
     Mode = BindingMode.OneWay,
     Path = new PropertyPath("Color"),
     Converter = new ColorToBrushConverter()
    };


    Could you help me?
    Regards,
    Olivier


  2. Olivier Masset
    Olivier Masset avatar
    3 posts
    Member since:
    Oct 2009

    Posted 08 Nov 2011 Link to this post

    sorry I forgot the end of the source code:

    Code behind:
    ChartLegend.UseAutoGeneratedItems = false;

       ...

    ChartLegendItem chartLegendItem = new ChartLegendItem();
    chartLegendItem.Label = dataSerie.LegendLabel;

    Binding markerFillBinding = new Binding(".")
    {
     Source = dataSerie,
     Mode = BindingMode.OneWay,
     Path = new PropertyPath("Color"),
     Converter = new ColorToBrushConverter()
    };

    BindingOperations.SetBinding(chartLegendItem, ChartLegendItem.MarkerFillProperty, markerFillBinding);
    //chartLegendItem.MarkerFill = new SolidColorBrush(Colors.Blue);
    trend.DefaultView.ChartLegend.Items.Add(chartLegendItem);

  3. Sia
    Admin
    Sia avatar
    756 posts

    Posted 11 Nov 2011 Link to this post

    Hi Olivier Masset,

    Please check the approach which my colleague described in the following forum thread and let me know whether it works for your scenario.

    If not please open a support ticket and send us a runnable project showing your exact scenario so that we can give you a more specific solution.
    Thank you in advance.

    Kind regards,
    Sia
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top