Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1415
BarSeries - Bind property to color
posted

Is there a way to bind a property to the "Brush" attribute on a BarSeries?

i.e.

public class MyModel

{

   public string label {get;set;}

   public int value {get;set;}

   public Brushes color {get;set;}

)

<ig:XamDataChart.Series>
   <ig:BarSeries ItemsSource="{Binding Data}" ValueMemberPath="value" Brush="{Binding Path=color}"/>
</ig:BarSeries>

Parents
  • 34830
    Verified Answer
    Offline posted

    Hello PMac,

    I have been investigating into your requirement and I am under the impression that you are looking to define a Brush on your underlying data item and bind the BarSeries to that so that each bar that is drawn for that particular BarSeries appears in a different color.

    If my impression is correct on this matter, this is not possible through a traditional binding, but you can do this using an event named AssigningCategoryStyle on the series. Note, that for this event to fire, you need to opt into it by setting the IsCustomCategoryStyleAllowed property on the BarSeries to true.

    This event will fire once per bar in the bar series each time the series draws, and the event arguments of the AssigningCategoryStyle event can net you the underlying data item for that bar using the GetItems method and allow you to change the Fill and Stroke of the bar’s color.

    I am attaching a sample project to demonstrate usage of this event. I hope it helps you.

    Please let me know if you have any other questions or concerns on this matter.

    XamDataChartBrushBindingCase.zip

Reply Children
No Data