A ViewModel1 takes data source dynamically from a Model by importing a .csv file containing data values and their distances. The ViewModel1 has two parameterized constructors. It creates a scatter series and stores it in the Series Collection.
private IEnumerable<Series> _myScatterSeries = new Collection<Series>();
A View1 is created in response to ViewModel1 using DataTemplates. View1 binds to MyScatterSeries property of ViewModel1 and shows the series representation in scatter chart.
View1.xaml:
<Grid Loaded="Grid_Loaded">
<ext:ChartExtension Style="{StaticResource ChartStyle1}" SeriesSource="{Binding MyScatterSeries}" />
</Grid>
I want to create a new View window (View2) and it should load the same scatter series created by ViewModel1 dynacamically, when I open View2 window. I tried using the same above code in View2, but it only shows chart, but now series data points. How can I bind MyScatterSeries property of the ViewModel1 to View2 dynamically?
I cannot use the following because it has problem with constructor arguments. View2.xaml-
<UserControl.DataContext>
<vm:ViewModel1/>
</UserControl.DataContext>
I also tried using DataTemplate, adding stack panel and wrapping the two Views, but it is not working.
As it is a ViewModel-First approach, I have created a new ViewModel (ViewModel2) for View2. But I don't know how to bind MyScatterSeries of ViewModel1 to ViewModel2, using code. Also, Can I use the same code of View1 to show scatter series in View2?