1
votes

XAML:

<Button Text="Submit" FontSize="{Binding BtnFontSize,Mode=Twoway}"/>

ViewModel:

string _btnFontSize;
        public string BtnFontSize
        {
            get { return _saveBtnFontSize; }
            set
            {
                _saveBtnFontSize = value;
                OnPropertyChanged();
            }
        }

while setting first time its works = > BtnFontSize="Large" after it not working => BtnFontSize="Small"

1

1 Answers

3
votes

Do the following changes and it should work:

Remove two-way binding as it is not needed

<Button Text="Submit" FontSize="{Binding BtnFontSize}"/>

In the OnPropertyChanged method pass the property name

 private double _btnFontSize;
 public double BtnFontSize
    {
        get { return _saveBtnFontSize; }
        set
        {
            _saveBtnFontSize = value;
            OnPropertyChanged(nameof(BtnFontSize));
        }
    }

And to get the default xamarin forms label font sizes you will use the NamedSize enum:

which should be something like below for eg to set the size to Medium you will do the following

BtnFontSize= Device.GetNamedSize (NamedSize.Medium, typeof(Label)),

Where typeof(Label) signifies the control you are using so when you need to set button font size you will pass button here