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
Dictionaries are made up of entries which are made up of a key and a value. Suppose you have a Dictionary<string, int>. The string part of each entry would be the Key, and the int part would be the value. This works similarly for the ValueMemberPath and the LabelMemberPath. By using a Dictionary<string, int>, you would set the ValueMemberPath to "Value" and the LabelMemberPath to "Key."
I have attached a modified version of the sample project I had originally provided you, which has the class Data derive from a Dictionary<string, int> instead of an ObservableCollection<DataItem>.
Hi,
Could you please let me know how can i bind dynamic data?
I mean, say I have a dictionary containing 10 values i.e Area<string,int> dictionary with 10 values.
How can I bind it to a pie chart (referring to the example given in the answers above).
Thanks,
Manu