操作 SurfaceScrollViewer 内容

发布于 2024-12-28 21:32:16 字数 1044 浏览 4 评论 0原文

我正在深入研究 WPF,但我无法解决多点触控的一些问题。
我有两个关于 SurfaceScrollViewer 的问题。

首先更简单:我正在使用 SurfaceScrollViewer 显示一张大照片,因此我可以平移,但我不知道如何让内容在屏幕中心开始。我在 SScrollViewer 中找不到任何本机对齐属性。如果我给内容边距,它就会裁剪它。如果我做 RenderTransform 也是一样。如果我执行 LayoutTransform,它似乎不会发生变化。有什么想法吗?

我还想在 SurfaceScrollViewer 内部提供此内容缩放功能。实际上,我正在尝试使用 SSV 的弹性效果进行缩放和平移。我应该手动写出操作还是可以修补 SSV 中的功能以便能够缩放? SSV 似乎将第二次触摸吸收到了其平移功能中。我必须编写一个操作处理程序来向内容发送多次触摸,对吗?

我的代码现在看起来像这样:

<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>

非常感谢任何帮助。谢谢!

I'm diving into WPF here and I can't figure some things with multitouch.
I've got two questions about SurfaceScrollViewer.

Easier one first: I've got a large photo I'm displaying with SurfaceScrollViewer, so I can pan around, but I can't figure out how to get the content to start out centered in the screen. I can't find any native alignment properties in SScrollViewer. If I give the content margins, it crops it. Same if I do a RenderTransform. If I do a LayoutTransform, it doesn't seem to do change. Any ideas?

I also want to give this content Zoom functionality while inside SurfaceScrollViewer. Really I'm trying to zoom and pan with the elastic effects of SSV. Should I write the manipulations out by hand or can I patch the functions in SSV to be able to zoom? It seems like SSV absorbs 2nd touches into its panning function. I'd have to write a Manipulation handler to send multi touches to the content, right?

My code looks something like this right now:

<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>

Any help is much appreciated. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故事未完 2025-01-04 21:32:16

弄清楚第一部分:

scrollViewer.ScrollToHorizontalOffset(x);
scrollViewer.ScrollToVerticalOffset(y);

看起来我必须控制 SSV 上的操作事件才能添加缩放。

figured out the first part:

scrollViewer.ScrollToHorizontalOffset(x);
scrollViewer.ScrollToVerticalOffset(y);

looks like i'll have to control manipulation events on the SSV to add zoom.

病毒体 2025-01-04 21:32:16

找出第二部分,放大滚动查看器,

  • 处理滚动查看器上的触地事件,
  • 向表面滚动查看器发送一次触摸,
  • 向内容发送两次触摸
  • 对内容
  • ,以滚动查看器作为容器,
  • 句柄进行操作,然后使用增量操作将 ScaleTransform 添加到内容
  • 不要忘记处理touchup事件

    private void FloorViewer_TouchDown(object sender, TouchEventArgs e) //捕获floorviewer上的触摸事件
    {
    
        Touch1ID = e.TouchDevice.Id - 16777216; ;
    
        if (Touch1ID == 0) //如果存在一次触摸,TouchDevice.Id 为 2^24,两次则 2^24+1 (这可能只是我的机器)
        {
            FloorViewer.IsManipulationEnabled = false;
            FloorViewer.ReleaseTouchCapture(e.TouchDevice);
            ScrollViewer.CaptureTouch(e.TouchDevice);
        }
        别的 {
            FloorViewer.IsManipulationEnabled = true;
            foreach(scrollViewer.TouchesOver 中的 TouchDevice 设备){
            ScrollViewer.ReleaseTouchCapture(设备);
            FloorViewer.CaptureTouch(设备);
            }
        }
        开始超时();
        e.已处理=真;
    }
    
    无效scrollViewer_TouchUp(对象发送者,TouchEventArgs e)
    {
        清除 ID();
        e.已处理=真;
    }
    
    私有无效clearID()
    {
        Touch1ID = 0;
    }
    
    私人无效 Floorview_TouchUp(对象发送者,TouchEventArgs e)
    {
        清除 ID();
        e.已处理=真;
    }
    
    //当触摸传递给它时,地板查看器上的操纵器
    私人无效scrollViewer_ManipulationStarting(对象发送者,ManipulationStartingEventArgs e)
    {
        e.ManipulationContainer=scrollViewer;
        e.已处理=真;
    }
    
    私有无效scrollViewer_ManipulationDelta(对象发送者,ManipulationDeltaEventArgs e)
    {
        双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.已处理=真;
    }
    

    boom!

figured out the second part to zoom inside scrollviewer

  • handle touchdown events on the scrollviewer
  • send one touches to surfacescrollviewer and
  • send two touches to the content
  • enable manipulations on content
  • handle manipulations with the scrollviewer as the container
  • then use the delta manipulations to add a ScaleTransform to the content
  • don't forget to handle touchup events

    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;
    }
    

    boom!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文