【问题标题】:OnPropertyChanged sometimes does not update UI in ListView, only after scroll or another activityOnPropertyChanged 有时不会更新 ListView 中的 UI,仅在滚动或其他活动之后
【发布时间】:2019-11-19 23:48:48
【问题描述】:

我有一个问题,当我使用列表项时,如果它们是可见区域,listview 不会重绘它们,仅在我将元素滚动出视图并返回之后才会反映,或者我已经点击了项目,它更新到 Xamarin v4 后出现,当我使用 Xamarin v3 时,一切都很好

此视频中的错误https://youtu.be/u-a1cWKywKI

模型.cs

 bool _CheckBoxIsVisible = false;
            public bool CheckBoxIsVisible
            {
                get
                {
                    return _CheckBoxIsVisible;
                }
                set
                {
                    if (_CheckBoxIsVisible != value)
                    {
                        _CheckBoxIsVisible = value;
                        OnPropertyChanged("CheckBoxIsVisible");
                    }
                }
            }

    #region INotifyPropertyChanged Implementation
            public event PropertyChangedEventHandler PropertyChanged;
            void OnPropertyChanged([CallerMemberName] string propertyName = "")
            {
                if (PropertyChanged == null)
                    return;

                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }
            #endregion

container.xaml

<controls:CheckBox Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" Margin="5,0,5,0" Type="Check" IsVisible="{Binding CheckBoxIsVisible}" IsChecked="{Binding IsSelect}" VerticalOptions="Center" HorizontalOptions="Center" />

container.cs

public ObservableCollection<MailModel> Items = new ObservableCollection<MailModel>();
    MailItemsListView.ItemsSource = Items;


foreach (var item in Items)
                    {
                        item.CheckBoxIsVisible= true;
                    }

【问题讨论】:

  • 如果您确定这是一个问题,为什么不通过 GithubXamarin.Forms 团队记录它
  • 是的,有人描述它是 21 小时前,但我该如何解决它github
  • @Artur,我可以在我身边重现此问题,我已报告此问题以获得 MS 支持,请稍等,在 github 中查看更新。

标签: c# listview xamarin.forms xamarin.android


【解决方案1】:

尝试更改主线程上的属性值,看看它是否有效。

【讨论】:

    【解决方案2】:

    如下更改 xaml 代码

    <controls:CheckBox Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" Margin="5,0,5,0" Type="Check" IsVisible="{Binding CheckBoxIsVisible, Mode=TwoWay}" IsChecked="{Binding IsSelect}" VerticalOptions="Center" HorizontalOptions="Center" />
    

    注意:-

    IsVisible="{Binding CheckBoxIsVisible, Mode=TwoWay}"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-04
      • 1970-01-01
      • 1970-01-01
      • 2018-06-01
      • 2016-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多