c# - WindowStartupLocation ="CenterScreen"时是否可以将窗口位置偏移一个值?

标签 c# wpf

过去的要求是窗口位于CenterScreen,但客户最近要求窗口现在稍微偏向其当前位置的右侧。

当前窗口的定义是:

我希望执行以下操作会起作用:

    public MyWindow()
    {
        InitializeComponent();

        // change the position after the component is initialized
        this.Left = this.Left + this.Width;
    }

但是当窗口出现在屏幕上时,它仍然处于相同的位置。

我是否需要将启动位置更改为Manual 并自行定位?如果是这样,我如何让它偏离中心?

最佳答案

处理 Loaded 事件,并将 this.Left = this.Left + this.Width; 放在那里:

public MyWindow()
    {
        InitializeComponent();

        this.Loaded += new RoutedEventHandler(MyWindow_Loaded);
    }


 void MyWindow_Loaded(object sender, RoutedEventArgs e)
        {
            this.Left = this.Left + this.Width;
        }

关于c# - WindowStartupLocation ="CenterScreen"时是否可以将窗口位置偏移一个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19725773/

相关文章:

c# - 不同aspx页面上的下拉列表需要 "relate"互相

c# - .NET C# 中的集合操作

c# - 您如何知道 ItemsControl 的哪个元素在 MVVM 中发送事件?

c# - WPF MessageBox 窗口样式

c# - 两个具有不同 View 模型的用户控件之间的 MVVM 绑定(bind)

c# - 从 View 模型中获取列表中的选定项目

c# - 开发基于 TCP/IP 的消息客户端的建议

c# - 线程同步

C# 使用递归从 List 创建 HTML 无序列表

c# - 如何暂停for循环,直到DispatcherTimer结束?