Can I change style properties at runtime?

I have this code in my page ;


  <syncfusion:SfPopup IsOpen="{Binding SettingsPopupOpen}" AppearanceMode="OneButton"               StaysOpen="True" HeightRequest="400"  ShowFooter="True" AcceptButtonText="OK" HeaderTitle="Opzioni" x:Name="popupStyle">
<syncfusion:SfPopup.PopupStyle>
         <syncfusion:PopupStyle MessageBackground="{AppThemeBinding Light=#fff,Dark=#333}"
                                MessageTextColor="{AppThemeBinding Light=#333,Dark=#aaa}"
                                FooterBackground="{AppThemeBinding Light=#fff,Dark=#333}"
                                HeaderBackground="{AppThemeBinding Light=#fff,Dark=#333}"
                                HeaderTextColor="{AppThemeBinding Light=#333,Dark=#aaa}"
                                />
     </syncfusion:SfPopup.PopupStyle>
     <syncfusion:SfPopup.ContentTemplate>
     ... etc

But if I change theme style dpes not updatem, I've also tryied setting in code behind via

 sfPopUp.BackgroundColor = App.Current.UserAppTheme == AppTheme.Light ? Colors.White: Color.FromHex("333333") ;

 sfPopUp.PopupStyle.HeaderTextColor= App.Current.UserAppTheme == AppTheme.Light ? Color.FromHex("333333") : Colors.White;

 sfPopUp.PopupStyle.AcceptButtonTextColor = App.Current.UserAppTheme == AppTheme.Light ? Color.FromHex("333333") : Colors.White;

when I change theme (via a SfSegmentedControl in its event "SelectionChanged") but also here no changes in my view.

Is possibile to update visual properties (background and textcolor in my specific case) when I change 


1 Reply

JR Jayashree Ravishankar Syncfusion Team September 13, 2024 10:22 AM UTC

Hi Denis,


We regret to inform you that the SfPopup control does not support dynamic style changes, as this is its default behavior. Therefore, we recommend closing the popup when the app theme is changed. Additionally, in .NET MAUI, there are no built-in notifications for theme changes. As a workaround, we suggest handling the RequestThemeChanged event at the sample level and closing the popup accordingly.


Please refer the following code snippet:

private void segmentedControl_SelectionChanged(object sender, Syncfusion.Maui.Buttons.SelectionChangedEventArgs e)

 {

     popup.IsOpen = false;

     if ( e.NewIndex == 0)

         App.Current.UserAppTheme = AppTheme.Light;

     else

         App.Current.UserAppTheme = AppTheme.Dark;

 

 }


(Or)

 public MainPage()

 {

     InitializeComponent();

     Application.Current.RequestedThemeChanged += Current_RequestedThemeChanged; ;

 }
 

 private void Current_RequestedThemeChanged(object? sender, AppThemeChangedEventArgs e)

 {

     popup.IsOpen = false;

 }


Please let us know if you have any other queries.


Regards,

Jayashree


Loader.
Up arrow icon