Forum Xamarin.Forms

Binding Mode property default value

JonAlzaJonAlza ESMember ✭✭✭

I'm seeing documentation about XAML, bindings and MVVM. The documentation about BindingMode says that:

OneWay: Indicates that the binding should only propagates changes from source (usually the View Model) to target (the BindableObject). This is the default mode for most BindableProperty values.

So, having a Entry which Text property binded to Message property of the viewmodel, if I want to update tha value of Message from the view I need this XAML:

<Entry Text="{Binding Message, Mode=TwoWay}"/>

But, I'm testing that and without setting Mode the value of Message is updated:

<Entry Text="{Binding Message}"/>

That works so, is the documentation wrong?

Tagged:

Best Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭
    Accepted Answer

    @azrinsani said:
    Don't set height? I thought it's always good to set height as it prevents layout calculation.

    Two things:
    1. You know you're replying to a 4 year old post, right? So you have to use some common sense when trying to decide if information provided for Xamarin.Forms 2 still applies to Xamarin.Forms 5.
    2. Not sure where you got the idea that setting height would avoid layout calculation. I mean, if nothing else there's still width... and how things wrap, and you have to calculate everything within that view... and... and... and

Answers

  • JonAlzaJonAlza ESMember ✭✭✭

    Thank you for the answer @ClintStLaurent, do you know if there is a link with default values for each control?

  • JonAlzaJonAlza ESMember ✭✭✭

    Thank you again!

  • azrinsaniazrinsani Member ✭✭

    @ClintStLaurent said:
    I would guess on the Xamarin site - but you'd have to root around a bit.
    Worst case if you REALLY had to know you could dig through the source code.

    Generally you don't need to go looking. Most of the controls behave as you would intuitively expect them to.
    An Entry is two way by default because that's just what you would expect.
    A Label is one way because... well... you can't set a label through the UI.
    And so on.

    The only time you really need to set binding mode explicitly is when you are deliberatly doing something out of the ordinary, like you want to use an Entry because you like the look but don't want the user to be able to enter a new value: That's a weird use-case for an entry so you probably need to explicitly set its binding mode.

    A good rule of thumb with XAML is don't set anything... Until you have a NEED to. Don't go setting every value under the sun until you have a hard reason to set it. Otherwise just let it go with as little as possible. Don't set the width and height: Let them auto adjust to the space available. Don't set a name, it shouldn't have one 99% of the time. Don't change the binding mode unless you have a solid behavior happening that you need to explicitly change. Minimal is good, its fast, it keep the control self adjusting and its less work on you.

    Don't set height? I thought it's always good to set height as it prevents layout calculation.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭
    Accepted Answer

    @azrinsani said:
    Don't set height? I thought it's always good to set height as it prevents layout calculation.

    Two things:
    1. You know you're replying to a 4 year old post, right? So you have to use some common sense when trying to decide if information provided for Xamarin.Forms 2 still applies to Xamarin.Forms 5.
    2. Not sure where you got the idea that setting height would avoid layout calculation. I mean, if nothing else there's still width... and how things wrap, and you have to calculate everything within that view... and... and... and

Sign In or Register to comment.