gpt4 book ai didi

c# - 如何在按钮上触发 "DragStarting"事件?

转载 作者:行者123 更新时间:2023-11-30 23:28:53 27 4
gpt4 key购买 nike

我正在开发“Windows 应用商店”应用程序。我希望能够拖动一个按钮来在网格单元格中设置一个值。这是按钮的声明:

<Button x:Name="button1"
Grid.Column="0"
Grid.Row="0"
Content="1"
HorizontalAlignment="Center"
Click="setGUICellValue"
CanDrag="True"
DragStarting="dragStarting" />

下面是事件处理程序的代码:

        private void dragStarting(UIElement sender, DragStartingEventArgs args)
{
draggedBtn = (Button)sender;
}

当我在“button1”按钮上单击并按住鼠标左键然后移动鼠标时(即当我开始拖动按钮时),事件处理程序不会被调用。 “单击”事件处理程序在我单击按钮时被调用,而在我尝试拖动它时不会被调用。

如何启动拖动事件?

最佳答案

在商店应用程序中,只能拖动 ListView 或 GridView 中的控件,这是一个非常烦人的限制。

但是,你很幸运,我已经创建了一个拖动页面,允许你将任何控件拖动到其中,看看它:https://github.com/gusmanb/DragPage

关于c# - 如何在按钮上触发 "DragStarting"事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35793029/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com