I just want to set windowstartuplocation to top right corner of desktop. Now to clear some things up, I saw this thread with same question:
Changing the start up location of a WPF window
Now I don't want to get confused to what they are referring as right or left, I want my application to start in top right corner,where right refers to MY RIGHT SIDE(not as if my desktop is a person looking at me and ITS RIGHT SIDE).So,
1.)setting left and top to 0 only is not a solution(brings app to left side not right)
2.)I tried using SystemParameters.PrimaryScreenWidth, but I can't perform operation to subtract the width of my app from this value at binding time.
Is there a way I can do it without going into much complexity?
Is there a way I can do it without going into much complexity?
The simplest way would be to setup your start location manually, and then set the Left
property in code behind:
<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"
Top="0">
</Window>
In your code behind:
public Window1()
{
InitializeComponent();
this.Left = SystemParameters.PrimaryScreenWidth - this.Width;
}
This is one place where I feel the simplicity of doing it in code outweights any disadvantages of introducing code behind.
By using WorkArea.Width make sure the width of the taskbar is taken into account (when placed on a side, left or right). By using this.Width or this.MaxWidth make sure your window never slips outside the work area, but both require their value be set (in xaml or in code behind) to not produce the value NaN (Not a Number) for this.Left.
public MainWindow()
{
InitializeComponent();
this.Left = SystemParameters.WorkArea.Width - this.MaxWidth;
}
<Window
... more code here ...
WindowStartupLocation="Manual" Top="0" MaxWidth="500" >
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With