gpt4 book ai didi

windows-8 - 在 Windows 8/WinRT 中实现 DragStarted DragDelta 事件

转载 作者:行者123 更新时间:2023-12-03 20:51:35 25 4
gpt4 key购买 nike

我如何附加 DragStarted DragDelta事件到网格 windows 8 / WinRT .我在 Windows 手机上用 GestureService.GetGestureListener() 做了同样的事情方法。我试图用 Windows 8 中的 ManipulationStarted 和 ManipulationDelta 事件替换代码。但结果不一样。在 Windows Phone 中,一次拖动它会进入 DragDelta 事件 2 次或更多次。但另一方面,在 Windows 8 中,在 ManupulationDelta 事件中,它只为类似的拖动操作触发一次。

最佳答案

是的,我想我知道你想要什么。

假设您有一些这样的 XAML:

<Grid Margin="50">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Rectangle Fill="Blue" x:Name="MyRect" />
</Grid>

您想围绕 Grid 移动该矩形通过拖动它。

只需使用此代码:
public MainPage()
{
this.InitializeComponent();
MyRect.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateY;
MyRect.ManipulationDelta += Rectangle_ManipulationDelta;
MyRect.ManipulationCompleted += Rectangle_ManipulationCompleted;
}

private void Rectangle_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
var _Rectangle = sender as Windows.UI.Xaml.Shapes.Rectangle;
var _Transform = (_Rectangle.RenderTransform = (_Rectangle.RenderTransform as TranslateTransform) ?? new TranslateTransform()) as TranslateTransform;
_Transform.X += e.Delta.Translation.X;
_Transform.Y += e.Delta.Translation.Y;
}

private void Rectangle_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
var _Rectangle = sender as Windows.UI.Xaml.Shapes.Rectangle;
_Rectangle.RenderTransform = null;

var _Column = System.Convert.ToInt16(_Rectangle.GetValue(Grid.ColumnProperty));
if (_Column <= 0 && e.Cumulative.Translation.X > _Rectangle.RenderSize.Width * .5)
_Rectangle.SetValue(Grid.ColumnProperty, 1);
else if (_Column == 1 && e.Cumulative.Translation.X < _Rectangle.RenderSize.Width * -.5)
_Rectangle.SetValue(Grid.ColumnProperty, 0);

var _Row = System.Convert.ToInt16(_Rectangle.GetValue(Grid.RowProperty));
if (_Row <= 0 && e.Cumulative.Translation.Y > _Rectangle.RenderSize.Height * .5)
_Rectangle.SetValue(Grid.RowProperty, 1);
else if (_Row == 1 && e.Cumulative.Translation.Y < _Rectangle.RenderSize.Height * -.5)
_Rectangle.SetValue(Grid.RowProperty, 0);
}

为了这:

enter image description here

希望我很接近!
祝你好运!

关于windows-8 - 在 Windows 8/WinRT 中实现 DragStarted DragDelta 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16667155/

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