title: Reducing multiple windows with mvvm
body: <p>I have a main window which have a few buttons, each button represent different object (of the same kind) which require different graph values.What is the best way to use one view and window in order to present all the different objects on the same graph, (one at time of course) depends on what button we choose.</p>
  
  <p>This is the view(deleted XAML code that seems to me unnecessary for the question):</p>
  
  <pre><code>&lt;layout:SampleLayoutWindow x:Class="AreaChart.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  ResizeMode="CanResizeWithGrip"
  xmlns:chart="clr-namespace:Syncfusion.UI.Xaml.Charts;assembly=Syncfusion.SfChart.WPF"
  xmlns:local="clr-namespace:PL" 
  xmlns:layout="clr-namespace:Syncfusion.Windows.SampleLayout;assembly=Syncfusion.Chart.Wpf.SampleLayout"
  UserOptionsVisibility="Collapsed"                   
  WindowStartupLocation="CenterScreen" Height="643.287" Width="1250.5"        
  Title="2017"&gt;
  &lt;Grid&gt;
  
  &lt;Grid.Resources&gt;
    ...........................................
      &lt;chart:AreaSeries x:Name="AreaSeries" EnableAnimation="True"
                        **XBindingPath="date" 
                        Label="Favourite"
                        YBindingPath="rate" 
                        ItemsSource="{Binding CurrenciesHis}"** 
                        ShowTooltip="True" &gt;
      &lt;chart:AreaSeries.AdornmentsInfo&gt;
      &lt;chart:ChartAdornmentInfo AdornmentsPosition="Bottom"  
                                        HorizontalAlignment="Center" 
                                        VerticalAlignment="Center" 
                                        ShowLabel="True"&gt;
      &lt;chart:ChartAdornmentInfo.LabelTemplate&gt;
                      &lt;DataTemplate&gt;
    ....................................
  &lt;ComboBox
  ItemsSource="{Binding YearsList}"
  SelectedItem="{Binding Year}"
  /&gt;
  </code></pre>
  
  <p></p>
  
  <p>This is the ViewModel:</p>
  
  <pre><code>public class ViewModel
  {
  public ViewModel()
  {
      Year = DateTime.Now.Year - 1;
      UpdateCurrencies();
  }
  
  protected void UpdateCurrencies()
  {
      //  Indexs that holds actuall api retrived values
      int i, j;
      //  cR- current rate in string format, urlContents - the whole Api retrived data
      string cR, urlContents;
      //  For api syntx, add 0 or not, depends on the current date syntax
      string c;
  
      CurrenciesHis = new ObservableCollection&lt;Model&gt;();//Model objects collection
  
      HttpClient client = new HttpClient();
  
      for (int l = 1; l &lt; 13; l++)
      {
          if (l &lt; 10)
              c = "0";
          else
              c = "";
  
          //  Use the public property Year, not the field _year
          var url = "http://data.fixer.io/api/" + Year + "-" + c + l + "-01?access_key=&amp;base=USD&amp;symbols=EUR&amp;format=1";
          urlContents = client.GetStringAsync(url).Result;
          i = urlContents.IndexOf("EUR");//Finds the desired value from api recived data
          j = urlContents.IndexOf("}");
  
          cR = urlContents.Substring(i + 5, (j - 2) - (i + 5));
  
          CurrenciesHis.Add(new Model() { rate = Convert.ToDouble(cR), date = "01/" + l.ToString() });
      }
  
      OnPropertyChanged(nameof(CurrenciesHis));
  }
  
  
  private int _year;
  public int Year
  {
      get { return _year; }
      set
      {
          if (_year != value)
          {
              _year = value;
              OnPropertyChanged(nameof(Year));
              UpdateCurrencies();
          }
      }
  }
  
  public ObservableCollection&lt;Model&gt; CurrenciesHis { get; private set; }
  
  
  public System.Collections.IEnumerable YearsList 
          =&gt; Enumerable.Range(DateTime.Now.Year - 30, 30).ToList().AsReadOnly();
  </code></pre>
  
  <p>}</p>
  
  <p>And this is the main window which we chose which currency we want to be represented on the graph that on the view by clicking a button that opens the window that contain the graph:</p>
  
  <pre><code>&lt;Window x:Class="PL.WindowMenu"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:local="clr-namespace:PL"
      mc:Ignorable="d"
      Title="WindowMenu" Height="643.287" Width="1250.5" WindowStartupLocation="CenterScreen"&gt;
  
  &lt;StackPanel Margin="0,0,2,2" RenderTransformOrigin="0.511,0.536"&gt;
      &lt;StackPanel.Background&gt;
          &lt;ImageBrush/&gt;
      &lt;/StackPanel.Background&gt;
      &lt;Grid Height="612" x:Name="NewGrid"&gt;
          &lt;Button Style="{StaticResource ButtonStyle}" HorizontalAlignment="Left" Height="92" Margin="346,221,0,0" VerticalAlignment="Top" Width="290"  Click="Button_Click"&gt;&lt;/Button&gt;
          &lt;Button Style="{StaticResource ButtonStyle}" HorizontalAlignment="Left" Height="92" Margin="346,221,0,0" VerticalAlignment="Top" Width="290"  Click="Button_Click2" Command="{Binding Path=ButtonClickCommand}" CommandParameter="{Binding}"&gt;&lt;/Button&gt;
          &lt;Button Style="{StaticResource ButtonStyle}" HorizontalAlignment="Left" Height="92" Margin="346,221,0,0" VerticalAlignment="Top" Width="290" Click="Button_Click3"&gt;&lt;/Button&gt;
       &lt;/Grid&gt;
   &lt;/stackpanel&gt;
   &lt;/window&gt;
  </code></pre>
  
  <p>ViewModel of the Main Window:</p>
  
  <pre><code> class RTViewModel : ObservableCollection&lt;RTModel&gt;
  {
      IBL bl;
  
      public ICommand ButtonClickCommand
      {
          get
          {
              return new EuroClickCommand();
          }
      }
  
      public void OpenGraph()
      {
  
          AreaChart.MainWindow myWindow = new AreaChart.MainWindow();
          myWindow.Show();
          //Window.GetWindow(this).Hide();
      }
  
      public RTViewModel()
      {
       }
  </code></pre>
  
  <p>EuroClickCommand:</p>
  
  <pre><code>  class EuroClickCommand : ICommand
  {
  
  
    public bool CanExecute(object parameter)
      {
          return true;
      }
      public event EventHandler CanExecuteChanged;
  
      public void Execute(object parameter)
      {
          var viewModel = (RTViewModel)parameter;
  
          viewModel.OpenGraph();
      } 
  
  }
  </code></pre>
  
  <p>What is the best approach to preform this task ?</p>