Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to set Image Source in C# to XAML Static Resource programmatically?
Posted

1 solution

If the resources are defined in a window, the window class has Resources[^] property which can be used.

So try something like
C#
myImageControl.Source = (System.Windows.Media.ImageSource)this.Resources["MyResourceName"];
 
Share this answer
 
Comments
Member 11521909 9-Sep-15 1:27am    
Thank You!
Sergey Alexandrovich Kryukov 9-Sep-15 2:19am    
5ed. (But hard-coding of "MyResourceName" is not good for maintainability. Any ideas?)
—SA

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