I have my WPF xaml as follows
- <Window
- 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">
- <Grid Height="224" Width="Auto">
-
- <CheckBox x:Name="Checkbox1" Width="100px" Height="25px" Content="Checkbox" Margin="90,-120,567,319"/>
- <CheckBox x:Name="Checkbox2" Height="25px" Content="Checkbox1" Margin="178,-120,457,319"/>
- <CheckBox x:Name="Checkbox3" Width="Auto" Content="Checkbox2" Margin="296,-120,309,319"/>
- <CheckBox x:Name="Checkbox4" Width="Auto" Content="Checkbox3" Margin="420,-120,213,319"/>
-
- <GroupBox Name="grp1" Header="Group1" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="92,56,0,98" Width="590" Height="70" IsEnabled="False">
-
- </GroupBox>
- <GroupBox Name="grp2" Header="Group2" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="92,136,0,18" Width="590" Height="70" IsEnabled="False">
-
- </GroupBox>
-
- </Grid>
- </Window>
-
I have written as follows to center the screen
- double width = window.ActualWidth;
- double height = window.ActualHeight;
-
- if (m_firstTime)
- {
- if (!Double.IsNaN(window.Width)) { width = window.Width; }
- if (!Double.IsNaN(window.Height)) { height = window.Height; }
-
- m_firstTime = false;
- }
-
-
- window.Left = (SystemParameters.WorkArea.Width - width) / 2
- + SystemParameters.WorkArea.Left;
- window.Top = (SystemParameters.WorkArea.Height - height) / 2
- + SystemParameters.WorkArea.Top;
-
But in my laptop it is going to the top so that few controls not getting visible so can some one help me to center on any screen resolution