Solve the problem of loading BitmapImage from Resources.resx resource file to Image.Source
Your attempt to assign the BitmapImage in Resources.resx to Image.Source failed because the Pack URI path is incorrect.
To use relative paths in Pack URIs, the logo.png file must be located in a folder named "Resources" in the Visual Studio project, and its build action must be set to "Resources". This "Resources" folder has nothing to do with Resources.resx and can be renamed at will.
So your code should look like this:
<code class="language-csharp">logoImage.Source = new BitmapImage(new Uri(@"pack://application:,,,/Resources/logo.png"));</code>
The above is the detailed content of How to Correctly Assign a BitmapImage from Resources.resx to Image.Source?. For more information, please follow other related articles on the PHP Chinese website!