2012-01-24 40 views
5

我想在WPF中的圖像控件上有一個背景圖像,例如,如果我加載透明的PNG,我仍然能夠看到背景。是否有可能,或者微軟完全放棄了WPF的這個特性,我必須依賴StackPanels/Grids /無論如何實現這一點?在WPF圖像控件上設置背景圖片?

回答

13

Image沒有財產,以便對,只是把一個BorderImage並設置Border.BackgroundImageBrush

+0

的確。有點煩人,但它有訣竅。謝謝 ! – pikzen

4

不,你需要圖像。將窗口背景設置爲圖像並將根元素背景設置爲圖像

<Window.Background> 
    <ImageBrush ImageSource="BackgroundImage.png"/> 
</Window.Background> 

<Grid.Background> 
    <ImageBrush ImageSource="ForegroundImage.png"/>  
</Grid.Background> 
2

如此處所測試的代碼所示,將窗口背景設置爲圖像畫筆。通知AllowsTransparency =「True」 And WindowStyle =「None」刪除邊框。

<Window x:Class="khaosInstallerWPF.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Height="616" Width="773" 
    ResizeMode="NoResize" Icon="images/khaos_Installer_UI.png" 
    AllowsTransparency="True" WindowStyle="None"> 
    <Window.Background> 
     <ImageBrush ImageSource="images\khaos_Installer_UI.png"/> 
    </Window.Background> 
    <Grid Margin="0,0,0,0"></Grid> 
</Window> 

獎勵:如果你使用的是形狀適合務必使你的表單拖拽

namespace khaosInstallerWPF 
{ 
    public partial class MainWindow : Window 
    { 
     public MainWindow() 
     { 
      InitializeComponent(); 
      MouseDown += delegate { DragMove(); }; 
     } 
    } 
}