Setting a background image on a WPF image control?
30,931
Solution 1
Image
has no property to allow for that, just put the Image
in a Border
and set the Border.Background
to an ImageBrush
.
Solution 2
No you need to images. Set the Window background to the image and set the root element background to an image
<Window.Background>
<ImageBrush ImageSource="BackgroundImage.png"/>
</Window.Background>
<Grid.Background>
<ImageBrush ImageSource="ForegroundImage.png"/>
</Grid.Background>
Solution 3
As shown in tested code here set the Window background to an image brush. Notice AllowsTransparency="True" And WindowStyle="None" to drop the border.
<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>
Bonus: If you are using a shaped for be sure to make your form draggable
namespace khaosInstallerWPF
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
MouseDown += delegate { DragMove(); };
}
}
}
Author by
pikzen
Updated on September 02, 2020Comments
-
pikzen over 3 years
I'm trying to have a background image on an image control in WPF, such as if I load a transparent PNG, I would still be able to see the background. Is it possible, or did Microsoft totally drop this feature with WPF and I have to rely on StackPanels/Grids/Whatever to achieve this ?