pbalaga
pbalaga

Reputation: 2068

WPF control size is larger than explicitly set width and height values

I created a Canvas with fixed Width and Height (256x256). Next to it I put an Image control displaying a 256x256 texture without stretching. How is it possible that actual sizes of both controls on the screen differ so much?

Here - is the screenshot illustrating size mismatch.

And here - the TestLines256.png in case someone liked to check it (and maybe point out that I'm stupid and this texture is 180x180 and not 256x256 as I claimed).

XAML with creation of the controls:

<Window x:Class="OversizedQuad.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" SizeToContent="WidthAndHeight">
<StackPanel Orientation="Horizontal">
    <Canvas Width="256" Height="256" Background="Red" />
    <Image Stretch="None" Source="TestLines256.png" />
</StackPanel>

Upvotes: 0

Views: 2196

Answers (1)

abhishek
abhishek

Reputation: 2992

WPF has Device Independent Pixel. Thus the size of pixel is different based on DPI settings. I guess for that reason the image size and Canvas size differs.

Check this :

http://www.dotnetfunda.com/articles/article882-wpf-tutorial--a-beginning--1-.aspx

Upvotes: 4

Related Questions