Xamarin.forms: Span Binding not updating even after OnPropertyChanged

Created on 24 Mar 2018  路  8Comments  路  Source: xamarin/Xamarin.Forms

Description

Span Binding not updating even after OnPropertyChanged

Steps to Reproduce

  1. ViewModel with INotifyPropertyChanged
  2. Bind Span inside formated text inside lable to a property
  3. change the value of the property and call OnPropertyChanged

Expected Behavior

the value updates

Actual Behavior

the value stays the same

Basic Information

  • Version with issue: 3.1.0.309646
  • Last known good version:
  • IDE: visual studio

@adamped Please check this one out since you did the #1850 PR for this

Thanks

Most helpful comment

+1
Default should be OneWay.

All 8 comments

@smartprogrammer93 - by default, the Span Text has OneTime Binding. Set the Binding Mode=OneWay and it will work.

It was recommended to default that way based on the premise that Span's are not likely to be updated, but I am not really convinced that would be the case anymore, or there are going to be a lot of support cases or issues around developers not knowing this @jassmith

@adamped

Thank you for your fast reply. I admit, i didn't try setting the binding Mode. but i do believe that having the default mode to be one time is a bit confusing. as the binding for a label is OneWay, and the span is just part of the label.

But that is just my personal opinion, I am sure you have your reasons to making it OneTime.

I will leave the issue open in case you would like to discuss this further. if not, please feel free to close it.

Yep, the OneWay fixed it for me. I agree this should be the default.

+1
Default should be OneWay.

+1 oneway would help

Funny, this just got me, too. I think OneWay would be better... but as long as this issue is searchable, it's an easy fix.

This has bitten me so many times. OneWay should be the default.

Text property has the default to OneWay, so I also think from a practical point of view, the default should be to OneWay too. The majority of scenarios for using binding on Span is when data is not available when Label is created.

But like a wise man has said many times _The ship has sailed_, I'm not sure if the default can be changed.
I don't think it would be a (much) breaking change however to change default from OneTime to OneWay, it would break few scenarios where the Text is not expected to be updated the 2nd time after bound value changed.

An alternate solution would be to have a static default value which can be modified: Span.TextDefaultBindingMode = BindingMode.OneWay and have the Xamarin Forms template updated to set it (kind of ugly, but effective if default value doesn't want to be changed).

Was this page helpful?
0 / 5 - 0 ratings