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
300
Bind XamPieChart ItemsSource to ViewModel Property
posted

Hi I Couldn't find way to Bind XamPieChart ItemsSource to my view model Property. Suppose we have ViewModel

namespace SomeNameSpace

{

     public class DataItem

    {
        public string Label { get; set; }
        public double Value { get; set; }
    }

    public class Data : ObservableCollection<DataItem>
    {
        public Data()
    {
        Add(new DataItem { Label = "Item 1", Value = 5 });
        Add(new DataItem { Label = "Item 2", Value = 6 });
        Add(new DataItem { Label = "Item 3", Value = 3 });
        Add(new DataItem { Label = "Item 4", Value = 7 });
        Add(new DataItem { Label = "Item 5", Value = 5 });
    }
}

public class MyViewModel
{

        public Data DataToBind { get; set; }

}

How can I Bind ItemsSource to DataToBind?

Parents
No Data
Reply
  • 34810
    Offline posted

    Hello Xetish,

    Thank you for your post!

    To bind your XamPieChart to your DataToBind property on your MyViewModel class, I would recommend first setting the XamPieChart's DataContext property to a new instance of MyViewModel. Then, you can use {Binding DataToBind} on the ItemsSource property of your chart to bind to this property. You will also need to instantiate your DataToBind property as a new Data() item. Finally, you will need to set the ValueMemberPath of the slices of your chart. In this case, you should set that property to "Value" so that it points at the Value property on your DataItem class.

    I have attached a sample project to demonstrate the above.

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

    Sincerely,
    Andrew
    Associate Developer
    Infragistics Inc.
    www.infragistics.com/support

    XamPieChartBindingCase.zip
Children