我的Xaml-Code中有一个ListView,当它的Binding正在改变时我想更新它。 我读了一些关于实现INotifyPropertyChanged的内容,但我并不熟悉如何做到这一点。
我在Xaml中的ListView:
<ListView IsItemClickEnabled="True"
x:Name="itemListView"
ScrollViewer.VerticalScrollMode="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"
AutomationProperties.AutomationId="ItemsListView"
AutomationProperties.Name="Items"
TabIndex="1"
Grid.Row="1"
Margin="-10,-10,0,0"
Padding="120,0,0,60"
ItemsSource="{Binding Source={StaticResource itemsViewSource}, Mode=TwoWay}"
SelectionChanged="ItemListView_SelectionChanged"
ItemTemplate="{StaticResource RepVSmallIcon70ItemTemplate}"
ItemContainerStyle="{StaticResource JobListViewItemStyle}"
IsRightTapEnabled="False"
ItemClick="itemListView_ItemClick" />
我的itemsViewSource资源:
<CollectionViewSource x:Name="itemsViewSource" Source="{Binding Items}"/>
我在c#中的项目:[编辑:错误的课程]
//public class JobDataGroup : repVReportsDataCommon
public class JobDataGroup : repVReportsDataCommon, INotifyPropertyChanged
{
private Func<ServiceJobItem, bool> _predicate;
public JobDataGroup(String uniqueId, String title, String subtitle, String imagePath, String description, Func<ServiceJobItem, bool> predicate)
: base(uniqueId, title, subtitle, imagePath, description)
{
_predicate = predicate;
}
[XmlIgnore]
public int JobCount
{
get { return this.Items.Count(); }
}
public ObservableCollection<ServiceJobItem> Items
{
get
{
//[EDIT: changed from IEnumerable to ObservableCollection
//return repVReportsDataSource.GetJobItems().Where(_predicate);
ObservableCollection<ServiceJobItem> collection = new ObservableCollection<ServiceJobItem>(repVReportsDataSource.GetJobItems().Where(_predicate));
return collection;
}
}
public IEnumerable<ServiceJobItem> TopItems
{
// Provides a subset of the full items collection to bind to from a GroupedItemsPage
// for two reasons: GridView will not virtualize large items collections, and it
// improves the user experience when browsing through groups with large numbers of
// items.
//
// A maximum of 12 items are displayed because it results in filled grid columns
// whether there are 1, 2, 3, 4, or 6 rows displayed
get { return this.Items.Take(12); }
}
}
答案 0 :(得分:0)
让您的商品返回ObservableCollection
,并且需要实施课程ServiceJobItem
INotifyPropertyChanged 界面,以便ListView通知何时进行了更改..