Ticket T435781
Visible to All Users

Refresh UI on theme change.

created 9 years ago (modified 9 years ago)

Hello ,
            I am using Two theme in my project. And for each theme i set different type of font .
which is save in my database.
i change font from my App.Xaml .

like this

XAML
<Style x:Key="TextBlockStyle" TargetType="{x:Type TextBlock}">           <Setter Property="FontFamily" Value="{Binding Path= FontFamilyAsPerTheme,Source={x:Static Application.Current}}"/> </Style>

and

XAML
<Style x:Key="BaseUniversalStyle" TargetType="{x:Type Control}">             <Setter Property="FontFamily" Value="{Binding Path= FontFamilyAsPerTheme,Source={x:Static Application.Current}}"/>  </Style>

But i have face one problem. When i change the theme on that time, some part of  UI has change the font but some are not.
when i restart my application then i get all font apply on UI.

so please suggest me solution where i can get change font run time.

for more detail i attach my video please check it. (I used MVVM pattern)
Thank you.

Show previous comments (1)
SK SK
Suvarna Kulkarni 1 9 years ago

    hello,
             i do did following step.

    I create one veritable on my App.cs

    public static string FontFamilyAsPerTheme { get; set; }

    and it's value i set on App.XAML design.

    <Style x:Key="TextBlockStyle" TargetType="{x:Type TextBlock}">
                <Setter Property="FontFamily" Value="{Binding Path= FontFamilyAsPerTheme,Source={x:Static Application.Current}}"/>
    <Setter Property="FontSize" Value="14"/>
            </Style>

    and

    <Style x:Key="TextBlockStyle" TargetType="{x:Type TextBlock}">
                <Setter Property="FontFamily" Value="{Binding Path= FontFamilyAsPerTheme,Source={x:Static Application.Current}}"/>
               <Setter Property="FontSize" Value="14"/>
            </Style>

    1. after that i have one form where i change my setting as per user choice.
      when user change theme then i set new font value to variable as follow.

    App.FontFamilyAsPerTheme = GeosApplication.Instance.UIThemeList.Where(uithe => uithe.ThemeName == ThemeManager.ApplicationThemeName).Select(ui => ui.FontFamily).FirstOrDefault();
    AllowUIToUpdate();

    1. AllowUiUpdate() method definition as follow :

    void AllowUIToUpdate()
            {
                DispatcherFrame frame = new DispatcherFrame();
                Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Render, new DispatcherOperationCallback(delegate (object parameter)
                {
                    frame.Continue = false;
                    return null;
                }), null);
                Dispatcher.PushFrame(frame);
            }

    i just follow this 3 step.

    in my project i have some class library which have some usercontrolls.
    so i want to apply font to all UI which is used.
    I thing by this description you can understand what i wan to say.
    thank you

    Andrey K (DevExpress Support) 9 years ago

      Hi,

      I still don't fully understand how it is connected with our themes or controls. Would you please elaborate on it? Also in the code you provided I don't see that you change our theme. Can you provide us with a working example that shows your application? This way we will be able to find the cause of the issue and provide you with a solution.

      Thanks,
      Andrey

      SK SK
      Suvarna Kulkarni 1 9 years ago

        see my app files.
        i have two theme.
        and on selection of white theme i pass following code.

        ThemeManager.ApplicationThemeName = "WhiteAndBlue";
        App.FontFamilyAsPerTheme = GeosApplication.Instance.UIThemeList.Where(uithe => uithe.ThemeName == ThemeManager.ApplicationThemeName).Select(ui => ui.FontFamily).FirstOrDefault();
        AllowUIToUpdate();

        Answers approved by DevExpress Support

        created 9 years ago

        Hello Suvarna,

        It seems that the issue is related to the fact that the FontFamilyAsPerTheme static property to which you are binding the FontFamily property in all your elements, does not raise any notifications about its changes. As a result, the corresponding bindings are updated only in those elements that are reloaded. It is not a limitation of our controls or our themes, but default behavior of Bindings and the WPF platform. I suggest that you refer to the Internet to determine how you can notify your users about changes in such a property. I found some articles for you:

        INotifyPropertyChanged and static properties
        INotifyPropertyChanged for static variable
        Binding static property and implementing INotifyPropertyChanged

        At first glance, it should be sufficient to create a class that is implemented according to the Singleton pattern and use it in your FontFamily property bindings: Implementing Singleton in C#.
        I hope you will find this information useful.

        Thanks,
        Andrey

          Show previous comments (3)
          Andrey Marten (DevExpress Support) 9 years ago

            Hello Suvarna,

            I've prepared a simple sample to illustrate that this approach works on my side correctly. Please refer to the attachment.

            Thanks,
            Andrey

            SK SK
            Suvarna Kulkarni 1 8 years ago

              Thank you for your support.
              It is work.

              Andrey Marten (DevExpress Support) 8 years ago

                I'm happy to hear that, Suvarna. You are always welcome.
                Andrey

                Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

                Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.