【问题标题】:ContentPage update 1st StackLayout based on 2nd SelectionContentPage 基于 2nd Selection 更新 1st StackLayout
【发布时间】:2016-09-06 18:55:19
【问题描述】:


我在 contentPage(Xamarin 表单)上有两个 StackLayout:StackLayoutA、StackLayoutB
StackLayoutA 包含:ListView、BtnForStackLayoutB
StackLayoutB 包含:选择标准(例如 2 个按钮:BtnA、BtnB)
两者都添加在 Main ContentPage 的 StackLayout 中。

BtnForStackLayoutB 是 Button 使得 StackLayoutB.IsvIsible=True/False;

基于我的点击 BtnA/BtnB 我想从 StackLayoutA 更新 ListView。 我正在使用以下代码更新列表视图的 ItemSource 但在页面上看不到

lisview.ItemsSource = null;
lisview.BeginRefresh();
lisview.ItemsSource = _SelectionRuleList;
lisview.EndRefresh();

我是否缺少任何其他设置?

【问题讨论】:

    标签: listview c#-4.0 xamarin xamarin.forms


    【解决方案1】:

    根据描述,我可以看到您正在使用 Xamarin.Forms 使用 Xamarin.Forms 开发的应用程序可以使用 ViewModels (MVVM)。

    鉴于要求,我能想到的就是在 MainViewModel 中有一个 List 并与 ListView 绑定。

    现在,当点击 BtnA/BtnB 时,各个函数实际上可以更新 MainViewModel 中的 List,从而更新 ListView。

    我创建了一个展示功能的示例: https://github.com/anubhavranjan/ListViewTest

    您可以在here 中阅读有关数据绑定的更多信息。

    【讨论】:

      猜你喜欢
      • 2014-11-27
      • 2022-11-04
      • 1970-01-01
      • 2018-08-27
      • 2020-09-07
      • 2011-07-12
      • 2011-03-19
      • 1970-01-01
      • 2018-09-11
      相关资源
      最近更新 更多