Obtenir les Propriétés de la Fenêtre dans le ViewModel

Je suis en train de construire une application WPF dont j'ai besoin pour obtenir la largeur, la hauteur et les lieux de la fenêtre de mon point de vue modèle. Je suis en utilisant le code XAML suivant:

<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}}">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Skins/MainSkin.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>

    <Grid x:Name="LayoutRoot">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="13*" />
            <ColumnDefinition Width="265*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="25" />
        </Grid.RowDefinitions>
        <TextBlock FontSize="36"
                   FontWeight="Bold"
                   Foreground="Purple"
                   Text="{Binding Welcome}"
                   VerticalAlignment="Center"
                   HorizontalAlignment="Center"
                   TextWrapping="Wrap" Grid.Column="1" Margin="19,70,32,70" />
        <Button Grid.Row="1" Content="Capture" Grid.ColumnSpan="2" Command="{Binding Capture}" />
    </Grid>
</Window>

À mon avis, le modèle, les valeurs pour le Haut, la Gauche bien fonctionner, mais les propriétés Width et Height sont à la fois NaN. J'ai les propriétés de ce type pour chacun des attributs, je suis de liaison sur:

private double height;

public double Height
{
    set
    {
        height = value;
    }
}

Aucune idée pourquoi les valeurs sont de retour à la NaN? Plus important encore, que puis-je faire pour obtenir les valeurs que je suis à la recherche d'?

EDIT: je réalise que c'est un peu hors sujet, mais j'ai besoin d'une capture d'écran de l'application à partir du modèle de vue. Le modèle de vue contient des propriétés supplémentaires que je n'ai pas le coller, mais qui sont nécessaires pour mettre en œuvre les fonctionnalités souhaitées. Pour les curieux, voici ma méthode pour capturer l'écran:

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
}
InformationsquelleAutor senfo | 2011-10-04