I have my WPF xaml as follows
- 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:WPFApp1"
- xmlns:Usercontrols="clr-namespace:WPFApp1.Usercontrols" x:Class="WPFApp1.Window1"
- mc:Ignorable="d"
- Title="Window1" Width="763" Height="950" ResizeMode="NoResize" Loaded="Window_Loaded">
-
"224" Width="Auto"> -
"Checkbox1" Width="100px" Height="25px" Content="Checkbox" Margin="90,-120,567,319"/> -
"Checkbox2" Height="25px" Content="Checkbox1" Margin="178,-120,457,319"/> -
"Checkbox3" Width="Auto" Content="Checkbox2" Margin="296,-120,309,319"/> -
"Checkbox4" Width="Auto" Content="Checkbox3" Margin="420,-120,213,319"/> -
"grp1" Header="Group1" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="92,56,0,98" Width="590" Height="70" IsEnabled="False"> -
"grp2" Header="Group2" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="92,136,0,18" Width="590" Height="70" IsEnabled="False">
I have written as follows to center the screen
- double width = window.ActualWidth;
- double height = window.ActualHeight;
- if (m_firstTime) // First time ActualWidth and ActualHeight is not set
- {
- if (!Double.IsNaN(window.Width)) { width = window.Width; }
- if (!Double.IsNaN(window.Height)) { height = window.Height; }
- m_firstTime = false;
- }
- // Set Left and Top manually and calculate center of screen.
- window.Left = (SystemParameters.WorkArea.Width - width) / 2
- + SystemParameters.WorkArea.Left;
- window.Top = (SystemParameters.WorkArea.Height - height) / 2
- + SystemParameters.WorkArea.Top;

Amit GuptaRank #190 · 12.8K reputationPosted Nov 3, 2016, 1:17 AM EDT
Amit GuptaRank #190 · 12.8K reputationPosted Oct 29, 2016, 2:01 AM EDT
Pradeep SahooRank #489 · 5.1K reputationPosted Oct 29, 2016, 5:11 PM EDT
Devi51 reputationPosted Nov 2, 2016, 2:44 AM EDT
Amit GuptaRank #190 · 12.8K reputationPosted Nov 2, 2016, 12:04 PM EDT
Devi51 reputationPosted Nov 2, 2016, 10:01 PM EDT