我在这里潜入WPF,我无法用多点触控来解决一些问题 我有两个关于SurfaceScrollViewer的问题。
首先更容易:我有一张我正在使用SurfaceScrollViewer显示的大照片,所以我可以平移,但我无法弄清楚如何让内容以屏幕为中心开始。我在SScrollViewer中找不到任何原生对齐属性。如果我给出内容边距,就会裁掉它。如果我做一个RenderTransform也一样。如果我执行LayoutTransform,它似乎没有做更改。有任何想法吗?
我还希望在SurfaceScrollViewer中提供此内容缩放功能。我真的想用SSV的弹性效果进行变焦和平移。我应该手动编写操作还是可以修补SSV中的功能以便能够缩放?似乎SSV在其平移功能中吸收了第二次触摸。我必须编写一个Manipulation处理程序来向内容发送多个触摸,对吧?
我的代码现在看起来像这样:
<Grid x:Name="LayoutGrid" Width="1950" Height="1118" HorizontalAlignment="Center" >
<s:SurfaceScrollViewer x:Name="scrollViewer" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" >
<local:FloorView x:Name="floorViewer" Width="4209" Height="1442" >
<local:FloorView.LayoutTransform>
<TranslateTransform X="1000" />
</local:FloorView.LayoutTransform>
</local:FloorView>
</s:SurfaceScrollViewer>
</Grid>
非常感谢任何帮助。谢谢!
答案 0 :(得分:0)
弄明白第一部分:
scrollViewer.ScrollToHorizontalOffset(x);
scrollViewer.ScrollToVerticalOffset(y);
看起来我必须控制SSV上的操作事件才能添加缩放。
答案 1 :(得分:0)
想出第二部分来放大scrollviewer
不要忘记处理触摸事件
private void floorViewer_TouchDown(object sender, TouchEventArgs e) //catch touch events on floorviewer
{
Touch1ID = e.TouchDevice.Id - 16777216; ;
if (Touch1ID == 0) //if one touch present, TouchDevice.Id is 2^24, two then 2^24+1 (this might just be my machine)
{
floorViewer.IsManipulationEnabled = false;
floorViewer.ReleaseTouchCapture(e.TouchDevice);
scrollViewer.CaptureTouch(e.TouchDevice);
}
else {
floorViewer.IsManipulationEnabled = true;
foreach(TouchDevice device in scrollViewer.TouchesOver){
scrollViewer.ReleaseTouchCapture(device);
floorViewer.CaptureTouch(device);
}
}
StartTimeout();
e.Handled = true;
}
void scrollViewer_TouchUp(object sender,TouchEventArgs e)
{
clearID();
e.Handled = true;
}
private void clearID()
{
Touch1ID = 0;
}
private void floorview_TouchUp(object sender, TouchEventArgs e)
{
clearID();
e.Handled = true;
}
//manipulators on floorviewer when it gets touches passed to it
private void scrollViewer_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
{
e.ManipulationContainer = scrollViewer;
e.Handled = true;
}
private void scrollViewer_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
double oldScale = flrScale;
flrScale *= e.DeltaManipulation.Scale.X;
if (flrScale < .95 | flrScale > 2) flrScale = oldScale;
floorViewer.RenderTransform = new ScaleTransform(flrScale, flrScale, e.ManipulationOrigin.X + flrInitX, e.ManipulationOrigin.Y + flrInitY);
e.Handled = true;
}
吊杆!