2013-12-12 184 views
0

我需要將圖像設置爲WPF窗口的背景。我已經將它設置這樣的:將圖像的高度和寬度設置爲WPF背景

<Window x:Class="DiagramView" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Height="418" Width="1185" ResizeMode="NoResize" WindowStartupLocation="CenterScreen"> 
    <Window.Background> 
     <ImageBrush ImageSource="../Images/Med.jpg" ></ImageBrush> 
    </Window.Background> 
</Window> 

但如果我有高度和寬度的窗口,原單的圖像,在窗口中的圖像是不是不削理所應當的。我想這是因爲窗戶本身佔據了高度和寬度的一部分。我的屬性我應該使用與原單寬度/高度

回答

1

圖像,以便保留原始圖像尺寸設置Stretch屬性爲None

<Window.Background> 
    <ImageBrush ImageSource="../Images/Med.jpg" Stretch="None" /> 
</Window.Background> 
0

如果你看看ImageBrush Class頁面上MSDN上,您會看到有很多屬性可用於將圖像放置在Brush之內。以下是特別感興趣的定位:

AlignmentX
AlignmentY
彈力
Viewbox控件
ViewboxUnits
視窗
ViewportUnits

請查看鏈接頁面及其說明。

相關問題