zdimension
zdimension

Reputation: 1074

WPF: Image stretched when placed in StackPanel in button

I'm making a sort-of toolbar in WPF (StackPanel containing Buttons containing StackPanels containing Images and TextBlock...) Here is the code for one button :

<Button x:Name="btnGraph" FontWeight="Normal" Background="{DynamicResource accentColor}" BorderBrush="{DynamicResource accentColor}">
    <StackPanel>
        <Image Source="Resources/diagnostic_chart1.png" Stretch="None"/>
        <TextBlock HorizontalAlignment="Center" Text="Graph"/>
    </StackPanel>
</Button>

As you can see, the image in the button is stretched, but the same image code outside the button (in the container StackPanel), it works correctly : image

I've tried a lot of things, but nothing worked. Is there a way to make it works ?

EDIT: I also tried changing the DPI of images from 72 to 96, no effect.

Upvotes: 1

Views: 531

Answers (1)

Mike Strobel
Mike Strobel

Reputation: 25623

The image doesn't look stretched to me; the size seems right. It actually looks like it's rendering across pixel boundaries, giving it a blurred appearance. Try setting UseLayoutRounding="True" on your root visual.

Upvotes: 3

Related Questions