Path Geometry Clipping Equvalent in WinRT

后端 未结 5 487
长情又很酷
长情又很酷 2020-12-05 15:34

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 go

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 16:14

    So, let's be clear of the status of things.

    1. WinRT XAML is now supported on WP 8.1
    2. WP Silverlight XAML can do more than WinRT XAML
    3. For example, WP SL XAML can use custom paths for clipping
    4. WinRT XAML can only use rectangles for clipping
    5. Reason: Rectangles out-perform any custom shape, period
    6. The XAML team lets performance trump capability
    7. Today, the XAML team has no plans to change clipping

    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:

    enter image description here

    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:

    enter image description here

    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

提交回复
热议问题