how specify bitmapimage path in directory

zleug 51 Reputation points
2021-04-03T20:08:44.397+00:00

Hi All.
In my WPF VB project I have Resources folder where I'm keeping Dictionary.XAML file and some images. How to specify BitmapImage in the Dictionary file to have ability call it in some places in the project? I tried like this:
<BitmapImage x:Key="IMG_Logo" UriSource="/Resources/Logo.png" />
And WPF window I try to call it by:

<Image Source="{DynamicResource IMG_Logo}" Width="76" Height="40" Margin="10,10,0,10" />

But unfortunately it doesn't work and got an error:
"Could not find a part of the path 'C:\Resources\Logo.png."

How to fix the problem?

Thanks

Developer technologies XAML
{count} votes

2 answers

Sort by: Most helpful
  1. DaisyTian-1203 11,646 Reputation points
    2021-04-06T01:28:02.557+00:00

    You need to create a Folder named Resources and add a Logo.png image in it. Then you need to edit the image's Properties, choose content for Build Action and Copy if newer for Copy to Output Directory, you can refer below picture for the details:
    84685-capture.png


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Elmar 26 Reputation points
    2021-04-16T10:06:03.87+00:00

    Try to address the BitmapImage ressource in your XAML file as StaticRessource:

    <Image Source="{StaticResource IMG_Logo}" Width="76" Height="40" Margin="10,10,0,10" />
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.