Reputation: 3240
I can center a wpf window in somewhere in the primary screen or in the virtual screen. However, I want to stretch the window over the whole virtual screen and place e.g. a grid in the window in a way that it fills the primary screen. The following snipped shows how I stretch the window, add a grid and stretch the grid to fit the primary screen size, but how do I determine the position (i.e. margin) for the grid?
<Window x:Class="BC.Citrium.Screensaver.Saver.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Height="{x:Static SystemParameters.VirtualScreenHeight}"
Width="{x:Static SystemParameters.VirtualScreenWidth}"
Top="{x:Static SystemParameters.VirtualScreenTop}"
Left="{x:Static SystemParameters.VirtualScreenLeft}"
ResizeMode="NoResize" WindowStyle="None">
<Grid Name="mainGrid"
Height="{x:Static SystemParameters.MaximizedPrimaryScreenHeight}"
Width="{x:Static SystemParameters.MaximizedPrimaryScreenWidth}"
Margin="???"
Background="Bisque">
</Grid>
</Window>
I could draw two windows, one to fit the virtual screen and one above that to fit the primary screen, but that's not the nice way.
Upvotes: 2
Views: 2171
Reputation: 942187
The upper left corner of the primary screen is always at screen position (0, 0). Which makes the margin you want to use (-VirtualScreenLeft, -VirtualScreenTop). With adjustment for the window border width and the window caption height.
Upvotes: 2