开发者

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

开发者 https://www.devze.com 2023-01-14 06:44 出处:网络
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 bo

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>


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

0

精彩评论

暂无评论...
验证码 换一张
取 消