CareTaker22
CareTaker22

Reputation: 1310

Changing the start up location of a WPF window in XAML to Bottom-Right

Is it possible to set the manual startup location for a WPF window in XAML to start in the Bottom-Right corner of the screen? I can do it in code-behind, but when the window opens, it pops up at the manual location (middle-left of the screen) then it jumps to the bottom right of the screen and it does not look very good.

I can set the location in the Top-Left of the corner in XAML with this coding:

<Window x:Class="WpfApplication1.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="Window1" 
    Height="500" Width="500"
    WindowStartupLocation="Manual" 
    Left="0" Top="0">
</Window>

Can I do the same for the Bottom-Right corner of the screen with XAML coding to fit ANY screen size?

Upvotes: 4

Views: 7509

Answers (2)

Gopichandar
Gopichandar

Reputation: 2842

I think it is not possible to set it via xaml. But, You can set it even before the window got loaded that wont jumps from manual location.

public MainWindow()
{
    InitializeComponent();
    Left = System.Windows.SystemParameters.WorkArea.Width - Width;
    Top = System.Windows.SystemParameters.WorkArea.Height - Height;
}

Upvotes: 8

itzmebibin
itzmebibin

Reputation: 9439

Set WindowStartupLocation="Manual" in XAML.

Then in Window_Loaded set the position like,

private void Window_Loaded(object sender, RoutedEventArgs e)
 {
    var desktopWorkingArea = System.Windows.SystemParameters.WorkArea;
    this.Left = desktopWorkingArea.Right - this.Width;
    this.Top = desktopWorkingArea.Bottom - this.Height;
 }

Upvotes: 1

Related Questions