How can I bind the XamWebChart to a SeriesCollection. I'm getting data from a service, in Xml format, containing the values and styles for few series' with several datapoints.
I created SeriesCollection in my ViewModel. Now how should I bind my view to make it use the SeriesCollection to draw graphs.
Hi Graham,
Can you provide me the link where I can check the bug status/details? It is very important to us.
Are you sure you are changing the data context at the right level? In the example I posted, if I change the chart's DataContext the series are updated. Are you changing the data context above the element which you originally set it on? Do you have a sample you can provide that exhibits the behavior you are seeing?
The bug is in review, you can check its status at any point by contacting Developer Support and providing them the bug number 30475.
-Graham
This is my usercontrol,
<UserControl xmlns:my=.........> <UserControl.Resources> <local:ChartViewModel x:Name="chartViewModel"/> </UserControl.Resources> <igChart:XamWebChart DataContext="{StaticResource chartViewModel}" Series="{Binding ChartSeriesCollection}"/> </UserControl>
I have a framework where I need to pick the usercontrols then create and add them to the ui. There I'm creating this control as,
ChartUserControl ucChart = new ChartUserControl(); ChartViewModel vmChart = new ChartViewModel(); vmChart.ChartSeriesCollection = myChartSeriesCollection; ucChart.DataContext = vmChart; regionManager.AddToRegion("MainRegion", ucChart);
The problem I guess is, when I add the control to region, PRISM is creating the control, and setting the datacontext to the one available in the resources of the usercontrol, thus showing the initialization data always.
So how should I reset the datacontext to another one?
Does this problem exists in both DataVisualization and Silverlight XamWebCharts?
Your problem is that when you are setting the actual DataContext programmatically you are setting it at a higher level than you are setting it inside the user control. The DataContext set on the chart will take precedence over the UserControl's DataContext. You have to replace the DataContext at the same level or lower than it was originally set.
One way to resolve your problem would be to give the chart in your user control a name
e.g. x:Name="theChart"
and then instead of this line:
ucChart.DataContext = vmChart;
write
(ucChart.FindName("theChart") as FrameworkElement).DataContext = vmChart;
let me know how it goes.