3

I have one border inside which am having an image. on button click am rotating that image to 90 degrees. this is my original image enter image description here

The below is after rotation enter image description here

As you can after rotation my image doesn't fit into the border. I need it to be fill the border completely. What is am missing here?

user3610920
  • 1,582
  • 2
  • 13
  • 24

1 Answers1

5

I think, you are using RenderTransform to rotate the image.

Instead, use LayoutTransform.

See the sample:

<StackPanel>
    <Border Width="500" Height="300" BorderBrush="Black" BorderThickness="1">
        <Image Source="sombrero.jpg" Stretch="Fill" x:Name="img" HorizontalAlignment="Center" VerticalAlignment="Center">
        </Image>
    </Border>
    
    <Button Content="Rotate" Click="ButtonBase_OnClick"></Button>
</StackPanel>

Codebehind:

private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
    {
        img.LayoutTransform = new RotateTransform(90);
    }

Before:

enter image description here

After:

enter image description here

Hope this helps.

Community
  • 1
  • 1
Parag
  • 543
  • 1
  • 8
  • 18