Databindings doesn't work anymore

LouisBeaumontLouisBeaumont Member ✭✭
edited July 2018 in Xamarin.Forms

My app was perfectly working on both iOS and Android in Debug mode, I tried to use Release mode, now my app is broken (bindings doesn't work anymore).
I tried these solutions (tested on Android 7.0 - Samsung G S6 and iOS 10.3.3 - iPhone 5C) =>
Debug mode

...
Release mode

  • Turn on / off use shared runtime

Both mode

  • Try all linking options
  • Enable / disable proguard
  • Clean solution + uninstall app from device + rebuild
  • Add / remove internet permission

To make sure my code isn't wrong (all bindings were working perfectly before) =>

Page.xaml

<On Platform="Android">
    <ListView x:Name="FlowersView" ItemsSource="{Binding Flowers}" 
        HasUnevenRows="True"
        ItemTapped="FlowersView_ItemTapped"
        ItemTemplate="{StaticResource flowerDataTemplateSelector}"
        SeparatorColor="BlueViolet">
    </ListView>
</On>



// One label in the template of the ListView (correctly displayed)
 <Label Text="{Binding Title}"  VerticalOptions="CenterAndExpand" LineBreakMode="NoWrap" 
                               Style="{DynamicResource ListItemTextStyle}" 
                               FontSize="16"/>

Page.xaml.cs

BindingContext = viewModel = new MainViewModel(this);


 private void FlowersView_ItemTapped(object sender, ItemTappedEventArgs e)
 {

        // Some random things to try to change the UI
        Console.WriteLine($"BindingContext : {this.BindingContext}");
        ((FlowerBase)e.Item).IsVisible = !((FlowerBase)e.Item).IsVisible;
        Console.WriteLine($"IsVisible : {((FlowerBase)e.Item).IsVisible}");
        Random r = new Random();
        string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        ((FlowerBase)e.Item).Title = new string(Enumerable.Repeat(chars, 5).Select(s => s[r.Next(s.Length)]).ToArray());
        Console.WriteLine($"Flower title : {((FlowerBase)e.Item).Title}");
}

ViewModel.cs

ObservableCollection<FlowerBase> flowers;
public ObservableCollection<FlowerBase> Flowers
{
    get { return flowers; }
    set { flowers = value; OnPropertyChanged("Flowers"); }
}

FlowersBase.cs

/// <summary>
/// Abstract model to all flowers
/// </summary>
public abstract class FlowerBase : INotifyPropertyChanged
{

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
        {

            var changed = PropertyChanged;
            if (changed == null)
                return;

        }

        private bool isVisible = false;
        public bool IsVisible
        {
            get { return isVisible; }
            set
            {
                if (isVisible != value)
                {
                    isVisible = value;
                    OnPropertyChanged("IsVisible");
                }
            }
        }

}

The page is displaying correctly with the listview filled ... the binding doesn't work

Even when putting breakpoint on the setters, OnPropertyChanged is called, but the UI doesn't change.
Also tried to make a new project and import everything etc ... Nothing better ...
Hope someone can help me, it's a bit frustrating to lose days when the app was working ...

Best Answer

  • LouisBeaumontLouisBeaumont ✭✭
    Accepted Answer

    Okay ... I don't know how this line disappeared from my code ...

    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    

    That's so stupid :D

    Fixed.

Answers

  • LouisBeaumontLouisBeaumont Member ✭✭
    Accepted Answer

    Okay ... I don't know how this line disappeared from my code ...

    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    

    That's so stupid :D

    Fixed.

Sign In or Register to comment.