I am having trouble getting an image, as a resource, to show in a listBox element.
It looks like a lot of people are having trouble with it, it seems difficult to do, when to me it sounds like something that would be very common and easy to do.
I've got a file called 'home_icon.jpg' in a folder called 'images' within my resource, so: images/home_icon.jpg.
I've got a list box, for which the full code is shown below:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ListBox Height="253" HorizontalAlignment="Left" Margin="10,46,0,0" Name="listBox1" VerticalAlignment="Top" Width="481">
<ListBoxItem>
<StackPanel Orientation="Horizontal" >
<Image Source="" Width="50" Opacity="50" />
<TextBlock Margin="0,5,0,0" Text="13 Scale Hall Lane" Width="425" />
</StackPanel>
</ListBoxItem>
</ListBox>
<Label Content="Welcome to the house manager" Height="28" HorizontalAlignment="Left" Margin="14,12,0,0" Name="label1" VerticalAlignment="Top" />
</Grid>
</Window>
I've read a bit online, and I've learned to set the "Build action" for the image to "Resource.

Here is the view of my solution explorer, showing the image in a folder:

What do I put in the Source="" attribute for the Image on the stackpanel for it to show my image?
I've tried looking at the following resour开发者_如何学Cces and things just aren't sticking:
http://msdn.microsoft.com/en-us/library/aa970069.aspx#The_Pack_URI_Scheme
http://channel9.msdn.com/forums/TechOff/416423-WPF--How-to-load-image-from-resource
WPF image resources
- Build Action should be
Content. Copy To Output Directoryshould beCopy if newer;- Then absolute or relative paths should work ...
images/home_icon.jpgshould work orpack://application:,,,/images/home_icon.pngshould work.
加载中,请稍侯......
精彩评论