How can I position the window's position on startup to the right side of the user's screen?

后端 未结 6 1070
逝去的感伤
逝去的感伤 2021-02-19 11:17

I am currently creating a sidebar-like WPF application in C#. When a user starts the application, I would like the window to automatically position it\'s self to the side of the

6条回答
  •  执念已碎
    2021-02-19 11:57

    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;
        }
    }
    

    SystemParameters documentation

提交回复
热议问题