Jump to content

Error Setting Background Image in WPF

Hey everybody,

 

I don't understand this error message:

 

"Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '7' and line position '14'."

 

It's a Windows Presentation Foundation (WPF) in Visual Studio using Visual Basic.

 

Here's the code, I'm not sure I understand what's wrong:

 

<Window x:Class="MainWindow"
    Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.Background>
            <ImageBrush ImageSource="space.jpg"/>
        </Grid.Background>
 
    </Grid>
</Window>

ASRock B550M PG RIPTIDE       Corsair Vengeance 16 GB DDR4             TEAMGROUP MP33 1 TB NVME SSD

AMD Ryzen 5 5600X                   Antec DF700 Case                                 MSI Radeon RX 580 4 GB ARMOR OC

 

Link to comment
Share on other sites

Link to post
Share on other sites

A jpg image should be compatible, so make sure the path and filename is correct.

 

Also make sure the build action is set properly for the image. To do this, look at the properties of the image file in visual studio.

 

"Build Action" should be set to either "Content" or "Resources" (most people seem to say resources is the one that worked for them)

"Copy To Output Directory" might also need to be set to "Copy if newer"

Link to comment
Share on other sites

Link to post
Share on other sites

Thanks - it was strange.  Apparently I needed to put in the whole file path even though the image still loaded correctly before debugging

ASRock B550M PG RIPTIDE       Corsair Vengeance 16 GB DDR4             TEAMGROUP MP33 1 TB NVME SSD

AMD Ryzen 5 5600X                   Antec DF700 Case                                 MSI Radeon RX 580 4 GB ARMOR OC

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×