How to set the location of WPF window to the bottom right corner of desktop?

后端 未结 7 2015
太阳男子
太阳男子 2020-12-07 20:39

I want to show my window on top of the TaskBar\'s clock when the windows starts.

How can I find the bottom right corner location of my desktop?

7条回答
  •  青春惊慌失措
    2020-12-07 21:12

    @Klaus78 's answer is correct. But since this is first thing google pops up and if working in environments where screen resolution can change often such that your app runs on virtual desktops or virtual servers and you still need it to update its placement when the screen resolution changes I have found linking to the SystemEvents.DisplaySettingsChanged event to be beneficial. Here is an example using rx and you can put this in your constructor for your view.

            Observable
                .FromEventPattern(_ => SystemEvents.DisplaySettingsChanged += _, _ => SystemEvents.DisplaySettingsChanged -= _)
                .Select(_ => SystemParameters.WorkArea)
                .Do(_ =>
                {
                    Left = _.Right - Width;
                    Top = _.Bottom - Height;
                })
                .Subscribe();
    

提交回复
热议问题