Answered by:

Simulating scrollViewer's behavior using DirectX

Question

I'm working on a Windows store app. I have a SurfaceImageSource that I render to using DirectX. The content displayed is rather large, even though just a small part is displayed at once. So I'm trying to use a scrollViewer with an image in it that is binded
to that SurfaceImageSource to let the user scroll an zoom.

The problem is that I need to make the SurfaceImageSource very large to render all the content at once and to prevent it from getting blurred when zoomed in. It would be way more efficient if I could just respond to some kind of zooming and scrolling event
and then to re-render the displayed content with a different transform.

Does anyone understand me? :D Is there any way to achieve what I want without implementing every gesture and mouse input by Hand?

Monday, April 28, 2014 4:46 PM

Answers

This sounds like a good use for a
VirtualSurfaceImageSource rather than a SurfaceImageSource. That will allow rendering only the exposed part of the content rather then the whole thing. For more info on how to draw to a
VirtualSurfaceImageSource, including sample code, see
DirectX and XAML interop.

I finally succeeded using the method described in the "PetzoldBookBlog" (can't post link, somehow). I use the VirtualSurfaceImageSource and resize it every time the ScrollViewer my image is in fires the ViewChanging Event, according to the zoom-factor
passed. Then I change the DPI of the Direct2DContext.

All replies

This sounds like a good use for a
VirtualSurfaceImageSource rather than a SurfaceImageSource. That will allow rendering only the exposed part of the content rather then the whole thing. For more info on how to draw to a
VirtualSurfaceImageSource, including sample code, see
DirectX and XAML interop.

I achieved this by using a swapchain, like described in the XAML SwapChainPanel DirectX interop sample.

If I zoom in to far, like using a zoomfactor of 10, this seems to exceed the capabilities of my graphics card, the app crashes (ResizeBuffers returns e_invalidarg when passing a buffer size of 20000x20000). So is there any way to combine these two methods?

I finally succeeded using the method described in the "PetzoldBookBlog" (can't post link, somehow). I use the VirtualSurfaceImageSource and resize it every time the ScrollViewer my image is in fires the ViewChanging Event, according to the zoom-factor
passed. Then I change the DPI of the Direct2DContext.