【问题标题】:Dragging with a customized window使用自定义窗口拖动
【发布时间】:2013-01-27 23:32:03
【问题描述】:

我有一个 WPF 窗口,没有默认窗口“chrome”。

<Window x:Class="Genesis.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Genesis (Alpha)" Height="812" Width="917" Loaded="Window_Loaded"
    DataContext="{Binding RelativeSource={RelativeSource Self}}" Name="Genesis" Closing="Genesis_Closing"
    WindowStyle="None" BorderThickness="0" Margin="0" ShowInTaskbar="False" AllowsTransparency="True" Background="#F8F8F8"></Window>

由于没有用于拖动窗口的默认栏,我无法拖动窗口。如何使用新控件重新创建拖动?

【问题讨论】:

    标签: wpf styles draggable


    【解决方案1】:

    您需要使用Window.DragMove 方法。

    从上面的链接:

    允许通过鼠标左键向下拖动窗口到窗口客户区的暴露区域。

    类似这样的:

    private void Genesis_MouseDown(object sender, MouseButtonEventArgs e)
    {
        if (Mouse.LeftButton == MouseButtonState.Pressed )
            this.DragMove();
    }
    

    【讨论】:

    • 好答案.....另外,如果您想使用“新控件”拖动表单,您可以在表单中添加另一个网格元素。将其放置在您想要的位置,并将 MouseDown 代码添加到新网格中,而不是添加到窗口中。
    猜你喜欢
    • 2020-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-20
    • 2019-09-28
    • 1970-01-01
    • 1970-01-01
    • 2012-08-18
    相关资源
    最近更新 更多