1

I need to load an image file to WPF's dynamic resource programmatically because the directory which contains the image files can be moved.

How can I load an image to WPF's dynamic resource which is used like this: Source="{DynamicResource ...}" in XAML?

1 Answer 1

2

In XAML:

<Image Source="{DynamicResource MyDynamicImage}" />

In code:

var myimg = new BitmapImage(new Uri("SomeUriHere"));
Resources["MyDynamicImage"] = myimg;

(The Resources collection should be one which is in the scope of the Image of course, if you have a direct reference to the Image control you can also use the immediate Image.Resources)

Whenever you set a new object to that resource key the DynamicResource will update.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.