We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to get the dynamic theme change effect in numeric control inside the Xamarin.Forms text input layout (SfTextInputLayout)

Platform: Xamarin.Forms |
Control: SfNumericUpDown |
Published Date: August 27, 2020 |
Last Revised Date: August 27, 2020

This article explains how to dynamically change the theme when having a UI contains the  Syncfusion Xamarin Forms NumericTextBox inside the SfTextInputLayour as follows.

 

dynamic theme effect

 

In case of requirement to have a specific control’s theme effect, add the SfNumericTextBoxStyles and SfTextInputLayoutStyles by following the provided guidelines in this link.

 

[XAML]

        <ContentPage.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <syncTheme:LightTheme />
                <buttons:SfButtonStyles />
                <syncfusion:SfNumericTextBoxStyles/>
                <textInput:SfTextInputLayoutStyles/>
            </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
    </ContentPage.Resources>
    <StackLayout Margin="20" VerticalOptions="CenterAndExpand">
        <textinputlayout:SfTextInputLayout>
            <syncfusion:SfNumericTextBox  Value="123.45" />
        </textinputlayout:SfTextInputLayout>
        <Button  Text="Light" x:Name="button" Clicked="Button_Clicked"   
                 HorizontalOptions="Center"
                 VerticalOptions="Center" />
    </StackLayout>

 

On the button click, remove the previously added theme and add a new required theme to the merged dictionaries as follows.

 

[C#]

            
        private void Button_Clicked(object sender, EventArgs e)
        {
            ICollection<ResourceDictionary> mergedDictionaries = Application.Current.Resources.MergedDictionaries;
          
            if (button.Text == "Light")
            {
                var lightTheme = mergedDictionaries.OfType<LightTheme>().FirstOrDefault();
                if (lightTheme != null)
                {
                    mergedDictionaries.Remove(lightTheme);
                }
                mergedDictionaries.Add(new DarkTheme());
 
                button.Text = "Dark";
            }
            else
            {
                var darkTheme = mergedDictionaries.OfType<DarkTheme>().FirstOrDefault();
                if (darkTheme != null)
                {
                    mergedDictionaries.Remove(darkTheme);
                }
                mergedDictionaries.Add(new LightTheme());
               
                button.Text = "Light";
            }
        }

 

 

View the sample in GitHub.

 

See also


How to set a custom background, text, and border colors for the SfNumericTextBox

How to customize the font style of SfNumericTextBox

Localization in Xamarin Numeric Entry (SfNumericTextBox)

Number Formatting in Xamarin Numeric Entry (SfNumericTextBox)

Return Type in Xamarin Numeric Entry (SfNumericTextBox)

 

 

 

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon