How can I position the window's position on startup to the right side of the user's screen?
Description
You can use Screen
from System.Windows.Forms
.
So add reference to the System.Windows.Forms.dll
and System.Drawing.dll
. Then change the Left
and Height
property in the MainWindow_Loaded
method.
Sample
public MainWindow(){ InitializeComponent(); this.Loaded += new RoutedEventHandler(MainWindow_Loaded);}void MainWindow_Loaded(object sender, RoutedEventArgs e){ this.Left = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right - this.Width; this.Top = 0; this.Height = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;}
More Information
You can do this without referencing win forms assemblies by using SystemParameters
. In the code behind for your window XAML:
MainWindow() { InitializeComponents(); this.Loaded += new RoutedEventHandler( delegate(object sender, RoutedEventArgs args) { Width = 300; Left = SystemParameters.VirtualScreenLeft; Height = SystemParameters.VirtualScreenHeight; }}
in your xaml :
WindowStartupLocation="Manual"
in the constructor :
Left = System.Windows.SystemParameters.PrimaryScreenWidth - Width Top=0