title: Getting Window Properties in ViewModel
body: <p>I'm building a WPF application in which I have a need to get the width, height and locations of the window from my view model. I'm using the following XAML:</p>
  
  <pre><code>&lt;Window x:Class="ScreenCapture.MainWindow"
          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"
          mc:Ignorable="d"
          Height="{Binding Height, Mode=OneWayToSource, FallbackValue=300}"
          Width="{Binding Width, Mode=OneWayToSource, FallbackValue=300}"
          Title="MVVM Light Application"
          Top="{Binding Top, Mode=OneWayToSource}"
          Left="{Binding Left, Mode=OneWayToSource}"
          DataContext="{Binding Main, Source={StaticResource Locator}}"&gt;
      &lt;Window.Resources&gt;
          &lt;ResourceDictionary&gt;
              &lt;ResourceDictionary.MergedDictionaries&gt;
                  &lt;ResourceDictionary Source="Skins/MainSkin.xaml" /&gt;
              &lt;/ResourceDictionary.MergedDictionaries&gt;
          &lt;/ResourceDictionary&gt;
      &lt;/Window.Resources&gt;
  
      &lt;Grid x:Name="LayoutRoot"&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="13*" /&gt;
              &lt;ColumnDefinition Width="265*" /&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition /&gt;
              &lt;RowDefinition Height="25" /&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;TextBlock FontSize="36"
                     FontWeight="Bold"
                     Foreground="Purple"
                     Text="{Binding Welcome}"
                     VerticalAlignment="Center"
                     HorizontalAlignment="Center"
                     TextWrapping="Wrap" Grid.Column="1" Margin="19,70,32,70" /&gt;
          &lt;Button Grid.Row="1" Content="Capture" Grid.ColumnSpan="2" Command="{Binding Capture}" /&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;</code></pre>
  
  <p>In my view model, the values for the Top, Left work fine, but, the Width and Height properties are both NaN. I have properties like this for each of the attributes I'm binding on:</p>
  
  <pre><code>private double height;
  
  public double Height
  {
      set
      {
          height = value;
      }
  }</code></pre>
  
  <p>Any idea why the values are coming back NaN? More importantly, what can I do to get the values I'm looking for?</p>
  
  <p><strong>EDIT:</strong> I realize this is a bit off, but I need to capture a screenshot of the application from the view model. The view model contains additional properties that I didn't paste, but are necessary in order to implement the desired functionality. For the curious, below is my method for capturing the screen:</p>
  
  <pre><code>private void CaptureScreen()
  {
      int x = Convert.ToInt32(left);
      int y = Convert.ToInt32(top);
      int w = Convert.ToInt32(width);
      int h = Convert.ToInt32(height);
      Bitmap image = new Bitmap(w, h);
      Graphics graphics = Graphics.FromImage(image);
  
      graphics.CopyFromScreen(x, y, x, y, new Size(w, h), CopyPixelOperation.SourceCopy);
  
      // Do something with the image
  }</code></pre>