【问题标题】:Silverlight 4: image in datatemplate not appearing on design surfaceSilverlight 4:数据模板中的图像未出现在设计图面上
【发布时间】:2011-09-14 00:24:32
【问题描述】:

我正在尝试使用数据模板将图像的源绑定到列表框中的字符串。

当我运行应用程序时,我在浏览器中看到了图像,但在设计图面上看不到它。

有什么想法吗?

我创建了一个带有 3 行网格的示例用户控件。 在第 0 行我只是把图像 在第 1 行中,我将图像放入列表框项 在第 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>

【问题讨论】:

  • 我说的设计师是VS Web Developer Express SP1 IDE,不是blend

标签: silverlight image binding datatemplate designer


【解决方案1】:

只需将 Person.Name 属性更改为其他内容

【讨论】:

  • 嗨 Waleed,Person.Name 不是问题所在。问题与pictureurl有关
【解决方案2】:

一旦我在 Person 类中将 PictureUrl 属性定义为 ImageSource,VS IDE 中的设计器就会显示该图像。

公共类人 {
公共字符串名称 { 获取;放; }
公共 ImageSource PictureURL { 获取;放; } }

我从这里获得信息:

http://forums.silverlight.net/forums/p/231544/568130.aspx#568130

【讨论】:

    猜你喜欢
    • 2019-03-12
    • 1970-01-01
    • 1970-01-01
    • 2018-10-17
    • 2018-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-11
    相关资源
    最近更新 更多