Fody PropertyChanged - Binding bool IsVisible

AbesoddyAbesoddy Member ✭✭

Hello,

I have in my view an ListView with the property "IsVisible" and i want to make visible and invisible this ListView.

So I have this code in my view : <ListView x:Name="resultsList" IsVisible="{Binding ListViewIsVisible}">

I have in my ViewModel this code : public bool IsVisible { get; set; } public event PropertyChangedEventHandler PropertyChanged;

My ViewModel inherits well of INotifyPropertyChanged...

I use Fody Propertychanged, so my bool IsVisible must be notified after a modification ?

Thank you for your answers :)

Posts

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    > @Abesoddy said:
    > Hello,
    >
    > I have in my view an ListView with the property "IsVisible" and i want to make visible and invisible this ListView.
    >
    > So I have this code in my view :
    >
    > I have in my ViewModel this code : public bool IsVisible { get; set; } public event PropertyChangedEventHandler PropertyChanged;
    >
    > My ViewModel inherits well of INotifyPropertyChanged...
    >
    > I use Fody Propertychanged, so my bool IsVisible must be notified after a modification ?
    >
    > Thank you for your answers :)

    Your property is ListViewIsVisible not IsVisible
  • AbesoddyAbesoddy Member ✭✭

    Yes indeed I am deceived in my post, I have it in my code : <ListView x:Name="resultsList" IsVisible="{Binding IsVisible}">

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Stop.

    BIG red flags
    1 - Don't name properties matching existing properites on controls, or same as keywords etc. Its a recipe for disaster and confusion. The control has a property IsVisible - don't make an identical property in your ViewModel. You're not paying for names by the letter: So something not already in use.
    2 - Why does your control have a name? That is almost always the sign of someone doing 1990's patterns in a 2019 world.
    3 - Why is your ViewModel even aware of visibility? ViewModels don't know or care about UI. And they could be the backing for 10 different views: So which view would have something visible and which wouldn't. The UI should decide about visibility based on its own rules. The button to choose Male would be visible if the Gender property on your ViewModel were Male. Logic based on data. NOT the viewmodel micromanaging UI elements.
    4 - >I have in my ViewModel this code : public bool IsVisible { get; set; } public event PropertyChangedEventHandler PropertyChanged;
    Why? Dear god why? I go back to my statement about using 1990's coding techniques in a 2019 world. I implore you to stop and read up on modern MVVM design and work through several tutorials and learning exercises before you try to tackle architecting your own solution because you have several years of design patterns to catch up on.

  • AbesoddyAbesoddy Member ✭✭

    Very good advice but do not hesitate to give solutions and be nice :) So the management of the ui is done in the controller ?

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Have a good day.
    Best of luck with the solution.

    Again - Read up on modern coding paradigms and the expectations of Xamarin and MVVM - There is no controller in this pattern.

    Its far more involved than can be handled in a single thread - Thus the advice to stop, learn, do guided lesson plans etc.

  • HotdogHeadHotdogHead Member ✭✭

    I think you might be confusing this with MVC as there is no controller in Xamarin. If you want a good site to check about this try redpillxamarin.com and check the tutorials. Just spend a couple of hours here and there on it.

Sign In or Register to comment.