网格视图移动,但是当我想拖动到任何位置时,它会返回到开始位置。我究竟做错了什么?我想我差不多完成了拖拉。
代码:
private void gridSlider_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
var _GridView = sender as Windows.UI.Xaml.Controls.GridView;
_GridView.RenderTransform = null;
var _Column = System.Convert.ToInt32(_GridView.GetValue(Grid.ColumnProperty));
if (_Column <= 0 && e.Cumulative.Translation.X > _GridView.RenderSize.Width * .5)
{
_GridView.SetValue(Grid.ColumnProperty, 1);
}
else if (_Column == 1 && e.Cumulative.Translation.X < _GridView.RenderSize.Width * -.5)
{
_GridView.SetValue(Grid.ColumnProperty, 0);
}
var _Row = System.Convert.ToInt32(_GridView.GetValue(Grid.RowProperty));
if (_Row <= 0 && e.Cumulative.Translation.Y > _GridView.RenderSize.Height * .5)
_GridView.SetValue(Grid.RowProperty, 1);
else if (_Row == 1 && e.Cumulative.Translation.Y < _GridView.RenderSize.Height * -.5)
_GridView.SetValue(Grid.RowProperty, 0);
}
private void gridSlider_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
var _GridView = sender as Windows.UI.Xaml.Controls.GridView;
var _Transform = (_GridView.RenderTransform = (_GridView.RenderTransform as TranslateTransform) ?? new TranslateTransform()) as TranslateTransform;
_Transform.X += e.Delta.Translation.X;
_Transform.Y += e.Delta.Translation.Y;
}
Xaml代码:
<StackPanel Name="TransportControlsPanel" HorizontalAlignment="Center" Grid.Row="1" Margin="351,0,0,0" >
<GridView x:Name="gridSlider" Width="604" AllowDrop="True" HorizontalAlignment="Center" Height="92" VerticalAlignment="Center" Visibility="Collapsed" SelectionMode="None" ManipulationCompleted="gridSlider_ManipulationCompleted" ManipulationDelta="gridSlider_ManipulationDelta">
<Slider x:Name="timelineSlider" AllowDrop="True" Margin="200,0,10,49" Width="192" Height="25" VerticalAlignment="Bottom" HorizontalAlignment="Center" Visibility="Collapsed" Background="Gray"/>
</GridView>
</StackPanel>