I have a couple of Images configured as application resources.
When my application starts, the background of the main window is set via XAML:
<Window.Background>
<ImageBrush ImageSource="/myapp;component/Images/icon.png" />
</Window.Background>
If a given event occurs, I'd like to change this background to another resource ("/myapp;component/Images/icon_gray.png"
).
I've tried using two constants:
private static readonly ImageBrush ENABLED_BACKGROUND =
new ImageBrush(new BitmapImage(new Uri("/myapp;component/Images/icon.png")));
private static readonly ImageBrush DISABLED_BACKGROUND =
new ImageBrush(new BitmapImage(new Uri("/myapp;component/Images/icon_gray.png")));
... but naturally, I get an exception with Invalid URI.
Is there a simple way to change the background image (via this.Background = ...
) of a WPF window using either the pack Uri or the resource (i.e.: Myapp.Properties.Resources.icon
)?
What about this:
or alternatively, this:
The problem is the way you are using it in code. Just try the below code
You can find more details regarding this in
http://msdn.microsoft.com/en-us/library/aa970069.aspx
i just place one image in " d drive-->Data-->IMG". The image name is
x.jpg
:And on c# code type
(please put double slash in between path)
finally i got the background..
Here the XAML Version
I have been trying all the answers here with no success. Here is the simplest way to do it with ms-appx
Assets folder is in the first level of my project, so make sure to change the path as convenient.