我将 LongListSelector 控件与 ItemRealized Event 一起使用,它工作正常,但是当我更新分配给 LongListSelector 的 ItemSource 的列表时,LongListSelector 中的项目没有更新。
下面是我在 XAML 中使用的代码。
<phone:LongListSelector SelectionChanged="listBoxGroups_SelectionChanged_1" Grid.Row="1" x:Name="longListSelector" ItemTemplate="{StaticResource groupsItemTemplate}" Margin="0,100,0,0">
</phone:LongListSelector>
在后面的代码中。
public GroupsMainPage()
{
InitializeComponent();
longListSelector.ItemRealized += longListSelector_ItemRealized;
this.Loaded += GroupsMainPage_Loaded;
}
void longListSelector_ItemRealized(object sender, ItemRealizationEventArgs e)
{
if (!controller.IsLoading && longListSelector.ItemsSource != null && longListSelector.ItemsSource.Count >= 100)
{
if (e.ItemKind == LongListSelectorItemKind.Item)
{
if ((e.Container.Content as Result).Equals(longListSelector.ItemsSource[longListSelector.ItemsSource.Count -7]))
{
connectToWebService();
}
}
}
}
在收到来自 Web 服务的响应后,我只需执行以下操作。
private void WebServiceSuccessAction(Object obj)
{
GroupModel.getInstance().GetGroupResponse((GroupResponse)obj);
if (GroupModel.getInstance().GetGroupResponse().Response.errorCode == 0)
{
controller = new GroupController();
if (fetchNumberofGroups <= 100)
{
this.ResultList = controller.GetGroupList();
longListSelector.ItemsSource = this.ResultList;
}
else
{
controller.addNewGroupData();
this.ResultList = controller.GetGroupList();
}
}
else
{
List<Error> error = ConfigModel.getInstance().getConfigResponse().Response.data.errors;
foreach (Error err in error)
{
if (err.code == GroupModel.getInstance().GetGroupResponse().Response.errorCode)
{
MessageBox.Show(err.text);
}
}
}
}