1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Xamarin.Forms】ListViewのセルの縦幅を可変にする

Posted at

初めに

https://qiita.com/sun_bacon/items/6f74ef44c35c508791d1
こちらの記事に大変助けられました、圧倒的感謝。
こちらを参考に、実装していく中で実際にBindingしている値が変わった時を
検知するのをメモ代わりに記事にします。

検知するとこ

CustomViewCell.cs
public class CustomViewCell: ViewCell
    {
        protected override void OnBindingContextChanged()
        {
            base.OnBindingContextChanged();
            if(this.BindingContext != null && this.BindingContext is INotifyPropertyChanged)
            {
                (this.BindingContext as INotifyPropertyChanged).PropertyChanged += CustomPropertyChanged;
            }
        }

        protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            base.OnPropertyChanged(propertyName);
            if(propertyName == "RealCell")
            {
                ((DynamicListView)this.Parent).OnDataChanged(false);
            }
        }

        private void CustomPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            ((DynamicListView)this.Parent).OnDataChanged(true);
        }
    }

ListViewは「初めに」に記載している記事をご覧ください。
trueとfalseについては、表示後に子ViewをViewCell内に表示する際
どうしてもDelayを数ミリ秒設定しないとうまく反映されないので
表示後にProperty変わった時、DelayかけるためにFLGをつけてます。

最後に

なんで、Bindingしたら可変にならなくなるのか・・・。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?