Today I started porting the page turn sample created here for Windows Phone 7 to WinRT (XAML, C#) for helping this question posted in Stack Overflow. But during porting I got stuck with the clipping portion of page. In the windows phone sample they are using Path Geometry clipping for clipping the page. But in WinRT It seems only rectangle geometry is supporting for clipping option.
How can I achieve similar functionality like Path geometry clipping in WinRT?
You can download the sample windows phone code from here
Please find the Source code i Tried please download
In that Please find the class PageTurn.cs, I commented the code with issues, in:
void left_PointerEntered(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
//_workingOdd.Clip = _oddClipRegion;
//_workingEven.Clip = _evenClipRegion;
}
So, let's be clear of the status of things.
Now we understand the problem. Do we have other options?
If you want to clip an image, you are in luck. You can create a path element of any shape and paint the background with an image brush. This is not technically clipping, but you have the same effect.
That would render this:
But wait there's more. The ImageBrush itself can be transformed. Meaning you can perform a Translate on the image moving the image around within the path. Moreover you can also apply a rotate on the image.
First, consider an animation like the one FlipBoard does. That gives you a simple page flip animation that looks freaking awesome without actually requiring a complex clipping. Check out this demo: http://blog.jerrynixon.com/2012/12/walkthough-use-xamls-3d-planeprojection.html
Then again, you might simply just want to replicate that Demo. That's fine. The XAML below will give you exactly the effect you want. And it is easy to animate:
It would look like this:
Here's the XAML to get exactly the look of the demo you linked to:
Would look like this:
I am not sure how much tweaking this would take to get right, Stephan. My guess is... plenty. The good news is: you can animate transforms on the GPU so most of this should be accelerated. :)
// Jerry
I feel it needs to be said that for the "Path with ImageBrush Fill" technique it is basically impossible to get the image to align exactly as you want using transforms, because the exact position of the image (of the imagebrush) inside the path clip depends on the extents of the path including Stroke.
So for example if you have a Bezier Path, you would need to calculate the actual extents of that Bezier to be then able to determine the exact scale/translate transform to apply to the image.
Stroke seems innocent, but when you have sharp angles in your poly-line path, the stroke makes a sharp pointy triangle! But also only to an extent, since after the angle gets really sharp, the triangle is not so pointy anymore! So, you would need to replicate the exact algorithm that does the Stroke for a Path.
Finally, I do need to admit there is the option to duplicate your Path for the Stroke, so have one with ImageBrush Fill and the other one without but with Stroke.
For images - you can simply use an
ImageBrush
and use it to fill aPath
that has the desired geometry. For anything more complicated - useRenderTargetBitmap.Render()
to turn your XAML into a bitmap and go back to answer 1.Hope this helps to you.
Here is the XAML to get exactly the look of the demo you linked to:
Path Calcualtion
Image1
Image2
OutPut
You can enlarge the size of image by putting image1 and image2 grid in viewbox like below
I'm a bit late to give a more complete answer, but I got inspired and started working on a reusable control/page transition. The current prototype is working quite nicely with
RenderTransforms
andClip
Transforms
for nice independent animation support.I'll work on that reusable control for WinRT XAML Toolkit, but meanwhile you can check this code:
XAML
C#