Click here to Skip to main content
15,030,781 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Tutorials say to use something like this:
XAML
<Window.Background>
  <ImageBrush ImageSource="background.jpg" Stretch="Fill" />
</Window.Background>


But when I do this, i get an error:
"The property Background is set multiple times"

Removing Background property in <window>
Background="{DynamicResource MaterialDesignPaper}"

gives new error:
"An attribute name is missing"

Which successfully stops me from setting the background. Is there any bypass for these errors?

What I have tried:

the things mentioned in the window above
Posted
Updated 27-Feb-21 9:09am
Comments
Gerry Schmitz 27-Feb-21 11:16am
   
I guess you'll have to show "all" your XAML to prove it's not "set multiple times".

1 solution

Try creating an ImageBrush in the Window.Resources, and set Window.Background to the resource.

XML
<Window x:Class="WpfBackgroundImg.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
		^__highlight]Background="{DynamicResource backgroundImage}"[/highlight__^
        Title="MainWindow" Height="450" Width="800">
	<Window.Resources>
^__highlight]
		<ImageSource x:Key="imgSource">image_resource.jpg</ImageSource>
		<ImageBrush x:Key="backgroundImage" ImageSource="{DynamicResource imgSource}" Opacity="0.3"></ImageBrush>
[/highlight__^
	</Window.Resources>
    <Grid>
    </Grid>
</Window>
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900