Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How save Slider Value

Hello !
I have a slider that I want to change all font sizes of all my app pages when the user changes slider value!

But the slider value is not saved. And when I exit the screen or hit the back button, the value of the slider resets and returns to the default state!

How can I save the slider value?

I use View Model to change the slide!

Thank you in advance to those who help me!

The following code is my view model code:

class SliderChangeSizeFont:INotifyPropertyChanged
{

    public  event PropertyChangedEventHandler PropertyChanged;

    [NotifyPropertyChangedInvocator]
    protected virtual void FontSize([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }


    private int _changeSize;

    public int ChangeSize
    {
          get => _changeSize;


          set
          {
              if (_changeSize == value)
                   return;
              _changeSize = value;
               FontSize();
        }


    }


}
Tagged:

Answers

  • YelinzhYelinzh Member, Xamarin Team Xamurai
    edited February 18

    But the slider value is not saved. And when I exit the screen or hit the back button, the value of the slider resets and returns to the default state!

    The debugging test data will not be saved when closing the app. To fix this, try using Preferences or the local database to store the values.

    Store the status to the Preferences, then detect the value when launching the application.

    Preferences.Set("my_key", "my_value");
    var myValue = Preferences.Get("my_key", "default_value");
    //detect the value to set the style
    

    Tutorial:
    https://docs.microsoft.com/en-us/xamarin/essentials/preferences?tabs=android


    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

  • YelinzhYelinzh Member, Xamarin Team Xamurai

    @hopofana Hi, any updates? If you've solved the issue, please accept the helpful reply as the answer. It'll help others who face the similar problem. If you are facing some issues while implementing, try to post the particular error with the corresponding codes here.

Sign In or Register to comment.