Hi,
I have attached a simple Project, where I would like to display two data series in one chart. It works if I create the DataContext in the Code Behind file (MainWindow.xaml.cs). But I want to set the DataContext for the XamDataChart in the xaml file (MainWindow.xaml). For this I added
<ig:XamDataChart.DataContext> <local:ChartViewModel/> </ig:XamDataChart.DataContext>
But I doesn't work. I'm sure there is a simple solution, but I can't figure it out.
Thanks for your help.
Thomas
I also try to transfer the IG example
"(NetAdvantage 2012.2, Samples Browser) -> xamDataChart -> Performance -> Updating Data Points"
into my Project. But I it crashes, because the pointers of "m_ChartViewModels" are null.
I'm very confused.
Hello Thomas,
Thank you for your post. I have been looking into the sample applications that you have attached and it seems that the reason for the data to not be displayed in the XamDataChart, when you set the DataContext through xaml, is that the two collections that you are using as source for the series does not have items in them. When you create an instance of your view model through xaml, the constructor without parameters is used and since you are not adding data in the two collections, in that constructor, no data is displayed. I have modified the sample application that you have attached, in order to show how you can initialize your data in the constructor of your view model.
Regarding the second sample application that you have attached, it seems that the reason for the NullReferenceException that you are getting is that you are trying to access resources before their initialization. Since you are getting the two ChartViewModels defined in the Resources of the MainWindow, before the InitializeComponents method to be called, the Resources collection returns null for both objects. The “DataSource1” and “DataSource2” objects and all of the other elements of the MainWindow, are initialized in the InitializeComponents method and if you wish to access one of those elements, you can do that in after the InitializeComponents is called.
Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support