I had a quick game and it seems that setting the Windows Left and Top properties is ignored when setting WindowState.Maximized with a WindowState.Maximized form.
One way would be to ignore WindowState functions and create your own Maximize / Restore functions
A rough example.
public partial class MainWindow : Window { private Rect _restoreLocation; public MainWindow() { InitializeComponent(); } private void MaximizeWindow() { _restoreLocation = new Rect { Width = Width, Height = Height, X = Left, Y = Top }; System.Windows.Forms.Screen currentScreen; currentScreen = System.Windows.Forms.Screen.FromPoint(System.Windows.Forms.Cursor.Position); Height = currentScreen.WorkingArea.Height; Width = currentScreen.WorkingArea.Width; Left = currentScreen.WorkingArea.X; Top = currentScreen.WorkingArea.Y; } private void Restore() { Height = _restoreLocation.Height; Width = _restoreLocation.Width; Left = _restoreLocation.X; Top = _restoreLocation.Y; } private void Button_Click_1(object sender, RoutedEventArgs e) { MaximizeWindow(); } private void Button_Click_2(object sender, RoutedEventArgs e) { Restore(); } protected override void OnMouseMove(MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { DragMove(); } base.OnMouseMove(e); } }
Xaml:
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="74.608" Width="171.708" ResizeMode="NoResize" WindowStyle="None"> <Grid> <Button Content="Max" HorizontalAlignment="Left" Margin="0,29,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/> <Button Content="Restore" HorizontalAlignment="Left" Margin="80,29,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_2"/> </Grid> </Window>
Obviously, you will need to clear this code, but it works wherever the Taskbar is located. However, you may need to add some logic to get the correct Left , Top if the custom DPI font is more than 100%
source share