2
我有一个WPF窗口列表视图如下更改图像源
<ListView Name="lvInstructors" ItemsSource="{Binding Instructors}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="3">
</UniformGrid>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<StackPanel Orientation="Horizontal">
<Image Source="http://localhost:30870/Content/img/avatar1.jpg" Width="30px"></Image>
<TextBlock Text="{Binding InstructorName}" FontWeight="Bold" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Description}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Qualifications}" />
</StackPanel>
<StackPanel Orientation="Horizontal" Name="InstructorRating">
<TextBlock Text="{Binding Rating}" />
</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我需要改变图像源属性,它位于第一StackPanel的内部程序,我该怎么做?
为什么不将它绑定到教师的图像或图像来源属性?通过这种方式,您可以为您的教师列表中的每位教师获取头像/图像。 – Xeun
我需要从远程服务获取每个图像 –
这不是一个真正的原因,为什么你不应该通过绑定来做到这一点。您可能正在查询教师的服务,无论您是在那里获取图像还是源代码路径。或者你正在图像属性Getter(我不会建议) – Xeun