【发布时间】:2016-07-05 10:43:16
【问题描述】:
我目前在 listView 中使用自定义 Image 对象(<Image> 对象的包装器)。当新的列表视图项可见(已实现)时,我的自定义 Image 对象的属性不会改变。
例如,如果我的列表视图(包含 30 个具有不同图像 URL 和不同文本的项目)在第一个滚动条上有 3 个项目,那么第 10 个项目与第一个项目具有相同的图像。图像按 [1-9][1-9][1-9] 的顺序重复......但令我惊讶的是,所有 30 个 listViewItems 中的文本都不同。
在调试时,我发现我的图像对象的设置器仅在前 9 个项目中被调用。有人可以阐明其他系统组件(系统图像/文本块工作正常)如何获得新的元素值吗?
相关类属性的代码sn-p:
public sealed partial class CustomImage : UserControl
{
public static readonly DependencyProperty ImageSourceStringProperty = DependencyProperty.Register("ImageSourceString", typeof(string), typeof(CustomImage), new PropertyMetadata(null, new PropertyChangedCallback(ImageSourceStringChanged)));
public string ImageSourceString
{
get { return (string)GetValue(ImageSourceStringProperty); }
set
{
//THIS NEVER GETS HIT FOR ITEMS AFTER 9th ITEM
SetValue(ImageSourceStringProperty, value);
//{More code here}
}
}
}
Xaml Usage
<ListView ItemsSource="{Binding}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<custom:customImage x:Name="Img" ImageSourceString="{Binding ImgPath}"/>
<TextBlock Grid.Column="1" Text="{Binding Name}"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我是否错过了它应该如何工作?如果有不清楚的地方请告诉我,我可以澄清。
【问题讨论】:
-
链接到一个示例项目:onedrive.live.com/… 您可以在输出窗口中看到 getter 没有被命中列表的后面部分
标签: c# listview uwp win-universal-app winrt-xaml