I'm trying to bind an image's source to a string in a listbox with a data template.
When I run the application, I see the image in the browser, but I cannot see it on the design surface.
Any ideas?
I have created a sample user control with a 3-row grid. In row 0 i just put the image In row 1 i put the image into a listbox item In row 2 I put the image into a datatemplate in a listbox bound to a resource
On the design surface, I can see the image in rows 0 and 1, but not in row 2.
public class PersonCollection : List<Person>
{
}
public class Person
{
public string Name { get; set; }
public string PictureURL { get; set; }
}
<Grid x:Name="LayoutRoot" Background="White">
<Grid.Resources>
<mystuff:PersonCollection x:Key="PersonList">
<mystuff:Person Name="Rick" PictureURL="abc.jpg"/>
<mystuff:Person Name="Bob" PictureURL="abc.jpg"/>
</mystuff:PersonCollection>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Image Source="abc.jpg"/>
<ListBox Grid.Row="1">
<ListBoxItem>
<StackPanel Orientation="Horizontal">
<Image Source="abc.jpg"/>
</StackPanel>
</ListBoxItem>
</ListBo开发者_如何学Gox>
<ListBox Grid.Row="2" ItemsSource="{StaticResource PersonList}">
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding PictureURL}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
Just change the Person.Name Property to something else
Once I defined the PictureUrl property as an ImageSource in the Person class, the designer in the VS IDE showed the image.
public class Person
{
public string Name { get; set; }
public ImageSource PictureURL { get; set; }
}
Here's where I got the information from:
http://forums.silverlight.net/forums/p/231544/568130.aspx#568130
精彩评论