【问题标题】:Create button to move WPF window创建按钮以移动 WPF 窗口
【发布时间】:2017-07-18 01:29:02
【问题描述】:

我有一个无边框的 WPF 窗口,我现在正在使用这个答案来移动它:Move a borderless window in wpf

但我真的很想有一个按钮,当您单击并按住时,您可以拖动窗口。那可能吗?

谢谢。

【问题讨论】:

  • 应该和按钮一样工作。

标签: wpf


【解决方案1】:

只需将PreviewMouseDown 事件附加到按钮并使用类似代码

XAML

<Button PreviewMouseDown="Move" />

或代码隐藏

Button button = new Button();
button.PreviewMouseDown += Move;

代码

private void Move(object sender, RoutedEventArgs e)
{
    // "window" is the name of the window
    window.DragMove();
    e.Handled = true;
}

【讨论】:

    猜你喜欢
    • 2015-11-30
    • 1970-01-01
    • 1970-01-01
    • 2016-06-12
    • 2013-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多