[英]Change dragged element appearance during .Net MAUI draggesturerecognizer operation
How do I change the appearance of the XAML element that is displayed while being dragged during a drag & drop operation in.Net MAUI?如何更改 XAML 元素的外观,该元素在 .Net MAUI 中的拖放操作期间被拖动时显示?
Maybe I should ask to what extent the appearance of the dragged visual can be changed?也许我应该问一下,拖动的视觉对象的外观可以改变到什么程度?
Currently the dragged visual is basically a slightly transparent copy of the XAML element on which the DragGestureRecognizer is implemented.目前,拖动的视觉对象基本上是实现了 DragGestureRecognizer 的 XAML 元素的稍微透明的副本。 I'd like to replace that visual completely, or at least resize it.
我想完全替换该视觉效果,或者至少调整它的大小。
I've adapted this example for an MVVM implementation, but I can't seem to find a way to change the appearance of the dragged visual.我已将此示例改编为 MVVM 实现,但我似乎无法找到一种方法来更改拖动视觉对象的外观。
Thx谢谢
I tried the DragStartingCommand
which is executed when a drag gesture is first recognized.我尝试了在首次识别拖动手势时执行的
DragStartingCommand
。
Here is the code in.xmal file.这是.xmal 文件中的代码。 I create a rectangle.
我创建一个矩形。
<Rectangle Stroke="Red"
Fill="DarkBlue"
StrokeThickness="4"
HeightRequest="200"
WidthRequest="200"
x:Name="myrec" >
<Rectangle.GestureRecognizers>
<DragGestureRecognizer DragStarting="OnDragStarting" />
</Rectangle.GestureRecognizers>
</Rectangle>
Here is the code behind.这是后面的代码。 I drag the element then it will set the height to 12.
我拖动元素然后它将高度设置为 12。
void OnDragStarting(object sender, DragStartingEventArgs e)
{
Shape shape = (sender as Element).Parent as Shape;
e.Data.Properties.Add("Square", new Square(shape.Width, shape.Height));
myrec.HeightRequest = 12;
}
More commands you can use by refering to Add drag and drop gesture recognizers您可以参考添加拖放手势识别器使用更多命令
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.