Lorenzo Beronilla
Lorenzo Beronilla

Reputation: 55

WPF .net - Buttons look different when zoomed

I am developing a WPF .net app in visual studio and having an issue where the buttons and their shaders look different depending on how zoomed in I am. This applies to changing the resolution of the displays as well. I have attached a few screenshots illustrating the issue. Anybody know what's going on here?

incorrect(zoomed in) correct (zoomed out)

Upvotes: 0

Views: 276

Answers (2)

Prabhdeep Singh
Prabhdeep Singh

Reputation: 306

I've got this issue many times, I learnt a simple fix to this one day. All you have to do is add your Grid in your a ViewBox, then you have to set the ViewBox to have StretchDirection="Both" and Stretch="Uniform"

XAML

<Viewbox StretchDirection="Both" Stretch="Uniform">
    <Grid Height="720" Width="1280" >
     <!-- Your XAML Code Here. -->
    </Grid>
</ViewBox>

I know that you probably already know this, but just keep in mind that you need to add all this code in between <Window/>. Also my grid here is 720p, you can change that to the width and height you want.

What this does is adds the grid into a ViewBox. When you zoom in, it will zoom in evenly.

Upvotes: 1

David Bates
David Bates

Reputation: 31

It appears to me that this is based on a perspective issue (zoomed vs regular). Looking at the two images you provided, the button with 'D' text does not alter its perspective. Maybe this is due to the ambient area between the edge of the text area and edge the button. Have you tried changing the background of the button and text items separately?

Upvotes: 1

Related Questions