Grid with ItemsSource

CheegerCheeger RUMember ✭✭

I bind ItemsSourceProperty like this https://github.com/Manne990/XamTest/tree/master/XamTest/Views/TemplatedTableView
But this only works when items are changing. When order of items is changing, items are added or removed - grid is not refresh. Is there any other way to bind ItemsSource?

Answers

  • Sumit_SharmaSumit_Sharma USMember ✭✭✭

    Can you try one thing.

    I am not entirely sure that it would work, i haven't tried it.
    Instead of

    public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create(nameof(ItemsSource), typeof(IEnumerable<IEnumerable<object>>), typeof(TemplatedTableView), null);
            public IEnumerable<IEnumerable<object>> ItemsSource
            {
                get { return (IEnumerable<IEnumerable<object>>)GetValue(ItemsSourceProperty); }
                set { SetValue(ItemsSourceProperty, value); }
            }
    

    try

    public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create(nameof(ItemsSource), typeof(IObservable<IEnumerable<object>>), typeof(TemplatedTableView), null);
            public IObservable<IEnumerable<object>> ItemsSource
            {
                get { return (IObservable<IEnumerable<object>>)GetValue(ItemsSourceProperty); }
                set { SetValue(ItemsSourceProperty, value); }
            }
    

    **or **

    Use ObservableCollection while binding items to your grid.

    Please give it a try.

    Thanks

  • CheegerCheeger RUMember ✭✭
    edited September 25

    IEnumerable<IEnumerable<object>> it's not a mistake?
    it didn’t work for me and I did this:

      public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create(nameof(ItemsSource), 
         typeof(IEnumerable<object>), typeof(TemplatedTableView), null);
        public IEnumerable<object> ItemsSource
        {
            get { return (IEnumerable<object>)GetValue(ItemsSourceProperty); }
            set { SetValue(ItemsSourceProperty, value); }
        }
    

    Maybe problem is this?

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Did you acheve the propertyChanging and OnPropertyChanged event like following link.
    https://xamarinhelp.com/bindable-properties-xamarin-forms/

Sign In or Register to comment.