【发布时间】:2019-09-03 12:53:31
【问题描述】:
我正在使用带有项目源属性的 GridView,它是对象列表。最初,我分配出现在 UI 上的页面上的项目列表。但是当我对按钮单击执行一些操作并更新列表中的项目时,它不会在 UI 上更新,我需要返回并再次访问。
<grial:GridView
x:Name="ItemList"
Padding="10"
ColumnSpacing="10"
RowSpacing="10"
ColumnCount="{
grial:OnOrientationInt
PortraitPhone=2,
LandscapePhone=2,
PortraitTablet=2,
LandscapeTablet=2,
PortraitDesktop=2,
LandscapeDesktop=2
}"
VerticalOptions="Start"
ItemsSource="{ Binding Items ,Mode=TwoWay}"
Style="{ StaticResource ResponsiveLandscapeMarginStyle }">
<grial:GridView.ItemTemplate>
<DataTemplate>
<local:RegisterItemGridV2 />
</DataTemplate>
</grial:GridView.ItemTemplate>
</grial:GridView>
我的视图模型
public class LoadDistinctItemsViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private IList<Items> items;
public IList<Items> Items
{
get => items;
set
{
items = value;
NotifyPropertyChanged();
}
}
protected virtual void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public void LoadData(string _loadId, int _mode = 0)
{
Items = App.dataManager.GetLoadDistinctItems(_loadId, _mode);
}
}
我正在调用每次都在更新的 loadData,项目列表中的计数在增加,但在 UI 上没有更新。
【问题讨论】:
标签: xamarin gridview data-binding inotifypropertychanged