【发布时间】:2014-03-12 01:01:58
【问题描述】:
我有一篇示范文章。文章有一个属性ImagePath,而ImagePath 是Uri string 的数组。
在指定的页面中。我只想显示 ImagePath 列表的第一个图像。所以我像下面那样做,没有图像显示。
<Image Source="{Binding ImagePath.[0]}" Height="50" Width="50" Grid.Row="0" Grid.Column="0"
VerticalAlignment="Top" Margin="0,7,7,0"
Grid.RowSpan="2">
其他属性显示良好,有人可以帮助我吗?
型号如下:
public class Article
{
public List<string> ImagePath = new List<string>();
public string Subject;
public string Words;
}
我在我的 xaml 中的 longlistselector 中有图像控制
<phone:LongListSelector
x:Name="articleList"
Grid.Row="1"
Margin="0,0,-12,0"
DataContext="{StaticResource viewModel}"
ItemTemplate="{StaticResource ResultItemTemplate}"
ItemsSource="{Binding ArticleCollection}"
ItemRealized="articleList_ItemRealized"
SelectionChanged="LongListSelector_SelectionChanged"
>
</phone:LongListSelector>
<DataTemplate x:Key="ResultItemTemplate">
<Grid Margin="0,6,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Rectangle Fill="Gray" Height="50" Width="50" Grid.Row="0" Grid.Column="0"
VerticalAlignment="Top" Margin="0,7,7,0"
Grid.RowSpan="2">
</Rectangle>
<Image Source="{Binding ImagePath.[0]}" Height="50" Width="50" Grid.Row="0" Grid.Column="0"
VerticalAlignment="Top" Margin="0,7,7,0"
Grid.RowSpan="2">
</Image>
<TextBlock Text="{Binding Path=Subject, Mode=TwoWay}" Grid.Row="0" Grid.Column="1"
Foreground="{StaticResource PhoneAccentBrush}" VerticalAlignment="Top"/>
<TextBlock Text="{Binding Path=Words, Mode=TwoWay}" TextWrapping="Wrap"
Grid.Row="1" Grid.Column="1"
VerticalAlignment="Top"
/>
</Grid>
</DataTemplate>
【问题讨论】:
-
不确定应该有 .在那里!试试 ImagePath[0]。但我的建议是在 Article 类上添加一个额外的属性 - ImageToDisplay,这将返回列表中的第一个图像。这样您就可以在 XAML 绑定中使用该属性
标签: c# windows-phone-7 data-binding windows-phone-8 longlistselector