question

zleug-6581 avatar image
0 Votes"
zleug-6581 asked DaisyTian-1203 commented

how specify bitmapimage path in directory

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


dotnet-wpf-xaml
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@zleug-6581
Did you check the below answers? Do them work for you? If you still meet this error, please let me know.

0 Votes 0 ·
Elmar-4711 avatar image
0 Votes"
Elmar-4711 answered

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" />


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DaisyTian-1203 avatar image
0 Votes"
DaisyTian-1203 answered

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.


capture.png (93.2 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.