Image sources.
Hello, I'm currently developing a game in c# and i have several questions regarding images in WPF.
First, I'd like to know some help regarding this exception.
Secondly, is it possible to define multiple images in the XAML, but display them only when needed?
this is how my current image looks, it is inside a grid
13 Replies
Use designer, add the picture and look at the generated code behind
you are accessing testImage before InitializeComponent
but testImage is created in there
No. Designer should never be used.
$rulesofwpf
Make sure your image is marked as a resource
I clearly suggested for reasearch purpose
mmm.. right.. maybe it's not embbeded as compilation resource
ty yall so much
also another question, slightly unrelated
when making classes that need to access elements of the mainwindow from the XAML, i need to inherit the "Window" class too? Id like to make a class that contains refrences to all images in the XAML, for my own convenience
You can use bindings
what are those
this is inside a canvas, and this is the code thats supposed to change the source
this is where its supposed to show, but it doesnt
it is
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/controls/how-to-use-the-image-element?view=netframeworkdesktop-4.8 i used this as a source, except for when i want to change the image source later on
How to: Use the Image Element - WPF .NET Framework
Learn how to use the Image Element.
hello, i gave up and just made the source in the xaml, like this
now i want to control its visibility w the help of an external class
i saw that i can inherit the in a class and i can access the elements
however i tried changing the visibility and opacity at a certain point and it didnt work