Click here to Skip to main content
15,891,473 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
[no name] 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"
		Background="{DynamicResource backgroundImage}"
        Title="MainWindow" Height="450" Width="800">
	<Window.Resources>

		<ImageSource x:Key="imgSource">image_resource.jpg</ImageSource>
		<ImageBrush x:Key="backgroundImage" ImageSource="{DynamicResource imgSource}" Opacity="0.3"></ImageBrush>

	</Window.Resources>
    <Grid>
    </Grid>
</Window>
 
Share this answer
 
v3
Comments
Member 14111219 3-Mar-23 16:05pm    
Hello,
Both of these methods work for me, but neither embeds the jpg into the exe as a resource. Is there a way I can just distribute the exe with the jpg embedded?
Thanks!

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