问题描述
|
我正在尝试将图像的源绑定到带有数据模板的列表框中的字符串。
运行应用程序时,我在浏览器中看到了图像,但是在设计图面上看不到它。
有任何想法吗?
我创建了一个带有3行网格的示例用户控件。
在第0行中,我只是将图像
在第一行中,我将图像放入列表框项
在第2行中,我将图像放入绑定到资源的列表框中的数据模板中
在设计图面上,我可以在第0行和第1行看到图像,但在第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>
</ListBox>
<ListBox Grid.Row=\"2\" ItemsSource=\"{StaticResource PersonList}\">
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source=\"{Binding PictureURL}\"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
解决方法
只需将Person.Name属性更改为其他内容
, 在Person类中将PictureUrl属性定义为ImageSource之后,VS IDE中的设计器就会显示该图像。
公共类人
{
公共字符串名称{get;组; }
公共ImageSource PictureURL {get;组; }
}
这是我从中获得信息的地方:
http://forums.silverlight.net/forums/p/231544/568130.aspx#568130