Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have included an icon file inside my Resources.resx that I'd like to show on a TreeViewItem that is inside a stackpanel.

1)Can .ico files be used for this purpose? Or does it have to be .bmp or jpg?

2)What do you set the source as in XAML? The following code didn't work for me

<StackPanel Orientation="Horizontal">
    <Image Margin="2" Source="/Resources/Folder_Back.ico" />
    <TextBlock Margin="2" Text="{Binding ProgramName}"
     Foreground="White" FontWeight="Bold"/>
</StackPanel>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
716 views
Welcome To Ask or Share your Answers For Others

1 Answer

Here is a trick to access image in Resource file:

Accessing image from Resource File in XAML markup

First you need to add reference to project properties like this:

xmlns:properties="clr-namespace:MyProject.Properties"

And then access it via XAML like this:

<image source="{Binding Source={x:Static properties:Resources.ImageName}}" />

You can use PNG/JPG/BMP as well as ICO file but everyone recommend PNG.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...