【问题标题】:DragMove() and MouseDragElementBehaviour won't work in the same window?DragMove() 和 MouseDragElementBehaviour 不能在同一个窗口中工作?
【发布时间】:2012-04-29 21:16:20
【问题描述】:

我正在使用

创建一个 WPF/xaml 应用程序

WindowStyle="无"

因此我不得不使用

    protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
    {
        base.OnMouseLeftButtonDown(e);

        // Begin dragging the window
        this.DragMove();

使它可以在屏幕上拖动窗口。但是,我也想在我计划使用的窗口中制作可拖动的图像

    <Image HorizontalAlignment="Right" Height="65" Width="203" Margin="0,278.271,14.434,82.5" Source="Images/Implementation1.png" Stretch="Fill">
        <i:Interaction.Behaviors>
            <ei:MouseDragElementBehavior ConstrainToParentBounds="True"/>
        </i:Interaction.Behaviors>
    </Image>

问题是我不能让它们都在同一个窗口上工作,因为它们只有在另一个被关闭时才能工作。任何帮助将不胜感激。

【问题讨论】:

    标签: c# .net wpf xaml drag-and-drop


    【解决方案1】:

    您的OnMouseLeftButtonDown 是在整个窗口上定义的,因此会干扰MouseDragElementBehavior 的触发器。

    在窗口中添加Border,给它一个BackgroundTransparent 可以,只是不要让它没有背景),然后在边框上听MouseLeftButtonDown 事件。在事件处理程序中执行DragMove()

    你可以把边框作为窗口的标题,也可以放在内容的后面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-20
      • 2017-10-10
      • 2021-10-26
      • 2016-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多