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?
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,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Thanks for reply. And What if I use Dictionary instead ObservableCollection, What should I set to LabelMemberPath and ValueMemeberPath