![](/img/trans.png)
[英]how to give resize support to my custom control when explicitly set width and height in wpf
[英]WPF control size is larger than explicitly set width and height values
我創建了具有固定寬度和高度(256x256)的畫布。 在它旁邊,我放置了一個圖像控件,該控件顯示256x256紋理而不拉伸。 屏幕上兩個控件的實際尺寸怎么可能會有如此大的差異?
這是截圖,說明尺寸不符。
在這里 -TestLines256.png,以防有人喜歡檢查它(也許會指出我很愚蠢,此紋理是180x180而不是我聲稱的256x256)。
XAML與控件的創建:
<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具有與設備無關的像素。 因此,像素大小基於DPI設置而不同。 我猜正是因為這個原因,圖像尺寸和畫布尺寸不同。
檢查一下:
http://www.dotnetfunda.com/articles/article882-wpf-tutorial--a-beginning--1-.aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.