DragStarted
DragDelta
でイベントをグリッドにアタッチする方法windows 8 / WinRT
。メソッドを使用してWindows Phoneでも同じことを行いました GestureService.GetGestureListener()
。Windows 8 でコードを ManipulationStarted & ManipulationDelta イベントに置き換えようとしましたが、結果は同じではありません。Windows Phone では、1 回のドラッグで DragDelta イベントに 2 回以上入ります。一方、Windows 8 では、ManupulationDelta イベントで、同様のドラッグ操作に対して 1 回だけ発生します。
1375 次
1 に答える
10
ええ、私はあなたが何を望んでいるのか知っていると思います。
次のような 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);
}
このため:
私が近くにいることを願っています!頑張ってください!
于 2013-06-08T05:45:15.053 に答える