我正在使用MVVM模型来创建App。我已经实现了Zoom,当我选择它时我可以移动一个单元。但是我不确定如何实现滚动,到目前为止我已经实现了:
ZoomStartedCommand = new RelayCommand<ManipulationStartedEventArgs>(ZoomStart);
ZoomDeltaCommand = new RelayCommand<ManipulationDeltaEventArgs>(ZoomDelta);
ZoomCompletedCommand = new RelayCommand<ManipulationCompletedEventArgs>(ZoomCompleted);
public void ZoomStart(ManipulationStartedEventArgs e)
{
FrameworkElement Element = (FrameworkElement)e.OriginalSource;
}
public void ZoomDelta(ManipulationDeltaEventArgs e)
{
if (e.PinchManipulation != null)
{
Map.deltaZoom = Map.deltaZoom * e.PinchManipulation.DeltaScale;
}
else
{
FrameworkElement Element = (FrameworkElement)e.OriginalSource;
Point P = e.DeltaManipulation.Translation;
Map.TranslateX += P.X;
Map.TranslateY += P.Y;
}
}
public void ZoomCompleted(ManipulationCompletedEventArgs e)
{
FrameworkElement Element = (FrameworkElement)e.OriginalSource;
}
我的观点如下:
<Grid x:Name="Map" Width="1271" Height="1381.5">
<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="{Binding Path=Map.deltaZoom}" ScaleY="{Binding Path=Map.deltaZoom}"/>
<TranslateTransform X="{Binding Path=Map.TranslateX}" Y="{Binding Path=Map.TranslateY}"/>
</TransformGroup>
</Grid.RenderTransform>
<i:Interaction.Triggers>
<i:EventTrigger EventName="ManipulationStarted">
<cmd:EventToCommand Command="{Binding Path=ZoomStartedCommand}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
<i:EventTrigger EventName="ManipulationDelta">
<cmd:EventToCommand Command="{Binding Path=ZoomDeltaCommand}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
<i:EventTrigger EventName="ManipulationCompleted">
<cmd:EventToCommand Command="{Binding Path=ZoomCompletedCommand}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Canvas/>
</Grid>
然而,当我以这种方式实现它时,Scroll会滞后,以任何方式避免这种滞后?