2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
This article explains how to dynamically change the theme when having a UI contains the Syncfusion Xamarin Forms NumericTextBox inside the SfTextInputLayour as follows.
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"; } }
See alsoHow to set a custom background, text, and border colors for the SfNumericTextBox
|
2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.