Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how "Stretch" property of Image in WPF Effects Transform?

Tags:

wpf

how "Stretch" property of Image in WPF effects Transforms ?

I found that Stretch property of image effets the transforms applied to it. When stretch=fill, then everything is fine but if stretch=uniform, the transforms are chaged. I not getting why this happening. Plz explain.

Image 1

Image 2

CODE:

<Canvas Height="200" Width="200">
        <Image Height="50" Width="50" RenderTransformOrigin="0.5,0.5" Source="Image.jpg" Stretch="Fill">
            <Image.RenderTransform>
                <TransformGroup>
                    <RotateTransform Angle="200" />
                    <TranslateTransform X="100" Y="100"/>
                </TransformGroup>
            </Image.RenderTransform>
        </Image>
        <Rectangle Height="50" Width="50" RenderTransformOrigin="0.5,0.5" Fill="RoyalBlue" Opacity="0.5">
            <Rectangle.RenderTransform>
                <TransformGroup>
                    <RotateTransform Angle="200" />
                    <TranslateTransform X="100" Y="100"/>
                </TransformGroup>
            </Image.RenderTransform>
        </Rectangle>        
    </Canvas>

<Canvas Height="200" Width="200">
        <Image Height="50" Width="50" RenderTransformOrigin="0.5,0.5" Source="Image.jpg" Stretch="Uniform">
            <Image.RenderTransform>
                <TransformGroup>
                    <RotateTransform Angle="200" />
                    <TranslateTransform X="100" Y="100"/>
                </TransformGroup>
            </Image.RenderTransform>
        </Image>
        <Rectangle Height="50" Width="50" RenderTransformOrigin="0.5,0.5" Fill="RoyalBlue" Opacity="0.5">
            <Rectangle.RenderTransform>
                <TransformGroup>
                    <RotateTransform Angle="200" />
                    <TranslateTransform X="100" Y="100"/>
                </TransformGroup>
            </Rectangle.RenderTransform>
        </Rectangle>        
    </Canvas>
like image 785
Code0987 Avatar asked Dec 14 '25 14:12

Code0987


1 Answers

From my testing, it appears that this is just a bug in the way the Visual Studio designer previews this XAML.

I've taken your code and loaded it in both Visual Studio 2010 and in Expression Blend 4. In Visual Studio's designer, I see what you're talking about. In Expression Blend, the preview is correct.

Most importantly, when I run the application, it is rendered correctly. So I think you're ok. Just pretend like its not doing that or use Expression Blend when you have to work with this control.

like image 66
Tim Avatar answered Dec 18 '25 15:12

Tim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!