05-20-2013 08:48 PM - edited 05-20-2013 08:49 PM
Hi,all.
I'm using a TabControl to display two viewmodels in one graph. Both viewmodels contain a ObservableCollection<ChartCollection<double, double>> type datasource. Datasource I contains two ChartCollection, and datasource II contains one. The problem is when I switch the tabitem from I to II, the second plot generated by datasource I can still be seen in the graph. What can I do to solve that?
Thank you very much for your help!~
05-21-2013 10:08 AM
Based on your description, I created the following example with two tabs and two data source collections. However, switching between the two tabs shows the expected data. If you could provide more information about your setup, it would help to understand the issue you are seeing.
MainWindow.xaml
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ni="http://schemas.ni.com/controls/2009/xaml/presentation"
Title="MainWindow">
<TabControl>
<TabItem Header="Graph 1">
<ni:Graph Background="LightGreen" DataSource="{Binding Item1}" />
</TabItem>
<TabItem Header="Graph 2">
<ni:Graph Background="LightBlue" DataSource="{Binding Item2}" />
</TabItem>
</TabControl>
</Window>
MainWindow.xaml.cs
using NationalInstruments.Controls;
using System;
using System.Collections.ObjectModel;
using System.Windows;
namespace WpfApplication3 {
using Chart = ChartCollection<double, double>;
public partial class MainWindow : Window {
public MainWindow( ) {
var data1 = Observable( CreateChart( 1, 2, 3 ), CreateChart( 4, 5, 6 ) );
var data2 = Observable( CreateChart( 3, 2, 1 ) );
this.DataContext = Tuple.Create( data1, data2 );
InitializeComponent( );
}
private static Chart CreateChart( params double[] values ) {
var chart = new Chart( );
for( int i = 0; i < values.Length; ++i )
chart.Append( i, values[i] );
return chart;
}
private static ObservableCollection<T> Observable<T>( params T[] values ) {
return new ObservableCollection<T>( values );
}
}