Theme changing at runtime

15 posts, 1 answers
  1. Ronald
    Ronald avatar
    21 posts
    Member since:
    Dec 2007

    Posted 06 Nov 2012 Link to this post

    Hi, 

    I'm running into some problems when I try to change the theme at runtime.
    We're about to release our solution and have to implement a few themes.

    I also had to add a GanttView control for a module I had to integrate in our solution recently, so I had to use implicit theming I read.

     With the stylemanager I was able to apply the theme to the default windows controls:
    StyleManager.ApplicationTheme = ThemeManager.FromName(theme);
    StyleManager.SetBasedOn(((Style)Application.Current.Resources[typeof(CheckBox)]), StyleManager.ApplicationTheme);
    StyleManager.SetBasedOn(((Style)Application.Current.Resources[typeof(RadioButton)]), StyleManager.ApplicationTheme);
    //etc.

    My current code for theme changing looks like this:
    Application.Current.Resources.MergedDictionaries.Clear();
    var s = String.Format("/Telerik.Windows.Themes.{0};component/Themes/", theme);
     
    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri(String.Format("{0}System.Windows.xaml", s), UriKind.RelativeOrAbsolute) });
    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri(String.Format("{0}Telerik.Windows.Controls.xaml", s), UriKind.RelativeOrAbsolute) });
    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri(String.Format("{0}Telerik.Windows.Controls.Input.xaml", s), UriKind.RelativeOrAbsolute) });
    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri(String.Format("{0}Telerik.Windows.Controls.Navigation.xaml", s), UriKind.RelativeOrAbsolute) });
    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri(String.Format("{0}Telerik.Windows.Controls.RibbonView.xaml", s), UriKind.RelativeOrAbsolute) });
    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri(String.Format("{0}Telerik.Windows.Controls.GridView.xaml", s), UriKind.RelativeOrAbsolute) });
    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri(String.Format("{0}Telerik.Windows.Controls.GanttView.xaml", s), UriKind.RelativeOrAbsolute) });

    I've added 3 screenshots of the application:
    the first (fig1) shows the application started with the Expression_Dark theme.
    the second (fig2) shows the application when I switched to the Windows 8 theme.
    the third (fig3) shows the application started with the Windows 8 theme.

    I hope you will be able to give me some tips on how to get this dynamic theme changing working correctly. And if you'll need additional information I will gladly try to supply you this information.

    Best regards,
    Ronald
  2. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 06 Nov 2012 Link to this post

    Hi Ronald,

     

    Thank you for sharing this snippet with us! Actually there is a difference between Telerik StyleManager and
    implicit styles and how they work. Looking at the XAML mark-up provided you have mixed these techniques in some way. I recommend you to review the following forum thread "Difference implicit/non-implicit themes" which will shed some light on that matter.
    Can you please take a look at this thread and let me know in case there is something unclear?



    Regards,
    Vanya Pavlova
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Ronald
    Ronald avatar
    21 posts
    Member since:
    Dec 2007

    Posted 06 Nov 2012 Link to this post

    Hi Vanya,

    I started out with the non-implicit themes. after I implemented the Ganttview Control I had to use implicit theming.
    http://www.telerik.com/community/forums/silverlight/ganttview/ganttview-theme-problem.aspx

    so I turned to:
    http://www.telerik.com/help/silverlight/styling-apperance-implicit-styles-overview.html and
    http://www.telerik.com/help/silverlight/styling-apperance-themes-runtime.html

    I commented the first snipped out, so I'm not using the StyleManager.Application Theme anymore.
    (I tried to mix implicit and non-implicit but that wasn't very successfull.)

    But the default windows controls, like the CheckBox, RadioButton, TextBox, PasswordBox aren't styled.
    I've got the feeling I'm missing something.

    Best regards,
    Ronald
  5. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 06 Nov 2012 Link to this post

    Hi Ronald,

     

    Thank you for getting back to us! Actually you should not mix StyleManager and implicit themes. As described in the previously referenced forum thread if you go through with implicit styles you should use NoXAML binaries. After merging the corresponding ResourceDictionaries with desired styles everything should work as expected. Can you please try to replace the binaries in your project with NoXAML ones and let me know whether the issue still persists? If this does not help I believe that the best option here is to isolate the problem in a small runnable project and sent it back to us as an attachment in a new support thread. 



    Regards,
    Vanya Pavlova
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Ronald
    Ronald avatar
    21 posts
    Member since:
    Dec 2007

    Posted 06 Nov 2012 Link to this post

    Hi, I've created a small application with a few controls on it and it works like it should. The TextBoxes, CheckBoxes are displayed correctly.
    A RadWindow doesn't however...

    When I use the NoXAML Binaries on my solution,  (I had to change the reference path otherwise the original dll's kept beeing used.)
    the layout and controls are messed up.
    Buttons aren't shown in the ribbon, the childwindow isn't displayed only the content of this window, and the windows controls still don't use the themes.

    Edit: Whoops, I saw that I forgot to remove  <Style TargetType="CheckBox"/> ... etc. from the App.xaml.
    So, the windows controls are themed correctly now.
    After checking the RibbonView, it's almost working like it did previously.

    Hope you have some patience with me, this is the last thing I have to implement in our solution. (I kept postponing this... :-S)




  7. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 07 Nov 2012 Link to this post

    Hi Ronald,

    It seems that you've managed to fix the issue with RadWindow.. If you have any additional issues/questions, please let us know.

    Kind regards,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Ronald
    Ronald avatar
    21 posts
    Member since:
    Dec 2007

    Posted 08 Nov 2012 Link to this post

    Hi Yana, sorry for my late reply, have been very busy finishing our solution.

    I switched back to the old Telerik dll's and not the NoXaml one's.

    I had a problem with the ribbonview, I use a plugin's and based on license, global or user configuration the interface gets constructed.
    One module contains a Ribbontab and gets inserted in the main application, that didn't work with the NoXaml dll's.

    I could not solve the RadWindow issue with implicit theming, while it works if I create a small test application. It doesn't if try to implement it in our solution. I have really no idea why I can't get my Radwindows (located in several assemblies) to style correctly.

    So I reverted to the implicit theming with the non-implicit dll's. And addressed a few problems as a known issue, that hopefully will be corrected in a future release.

    A lot of people are breathing in me neck this week so I'm trying to finish some last requests and fix some bugs.
    If you got any idea how I can use RibbonTab as plugin in the NoXaml binaries or what could be the problem in our solution with the RadWIndows?

    I'll hope that I can release the solution to the testers tomorrow and perhaps next week I can attempt the correct usage of implicit theming again.

    Thanks for the assistance
  9. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 13 Nov 2012 Link to this post

    Hi Ronald,

    Unfortunately I am not sure I understand the scenario in which you're using the RadRibbonView control. Can you please elaborate on that part - "If you got any idea how I can use RibbonTab as plugin in the NoXaml binaries". Are you creating a PRISM/MEF application and adding tabs in the RibbonView control? Also, can you specify how does the NoXaml dlls behave with the RadRibbonTabs and why they don't work - do you see an error or an incorrect styling?

    As for the RadWindow - I guess that you're using it as a UserControl and in this case you need to add an additional Style as the TargetType is different. For more details you can check the Note at the bottom of this topic.

    All the best,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  10. Ronald
    Ronald avatar
    21 posts
    Member since:
    Dec 2007

    Posted 03 Dec 2012 Link to this post

    Hi Tina, 
     
    sorry for my late reply (I missed your post.)
    The problem was that I had very little time to implement this functionality. They wanted it but also wanted to release the product.
     
    I use MEF in the application to inject views and functionality. I have a couple of RadRibbonTabs views that can get inserted based on the configuration. Or are shared with the other module that is integrated in our application.
     
    I quickly tried to use the NoXaml dlls but when it didn't work immediately I switched back in order to complete the release. (With a known issue for switching themes.)
     
    I'm now fixing some minor issues and adding a bit more functionality. Hope I can get back to the the NoXaml dlls soon.
    Hoping also I can create a sample project where I can reproduce the problems I have.
     
    Again sorry for my late reply,
    Ronald

  11. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 05 Dec 2012 Link to this post

    Hi Ronald,

    I'm glad you managed to implement your solution for your release with the normal assemblies. But if you get back to the NoXaml assemblies approach, we'd really appreciate a sample solution as we'd like to help you implement your scenario using implicit styles.

    Kind regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  12. Ronald
    Ronald avatar
    21 posts
    Member since:
    Dec 2007

    Posted 05 Dec 2012 Link to this post

    Thanks, I will certainly do that.

    I will have to make changes in the behavior of my sample solution. Like I said when I create a simple project everything works like expected. So it might even work when I give it a second try (with more time on my hands).

    Perhaps you can help me with an issue I'm having with the Expression Dark theme.
    The caret for some input controls  (TextBox, RadDatePicker, RadComboBox with IsEditable) is hardly visibile (black).

    I have a resource dictionary for every theme with a customized RadUpload control and RadOutlookbar style that I merge when a theme is changed.

    In this dictionary I added the following Style for changing the TextBox properties:
    <Style TargetType="TextBox" BasedOn="{StaticResource TextBoxStyle}" >
        <Setter Property="CaretBrush" Value="White" />
        <Setter Property="SelectionBackground" Value="#335C85" />
        <Setter Property="SelectionForeground" Value="#83CDF6" />
    </Style>

    The strange thing is that the caret changes back to black after a few clicks (eg on a button).
    The selection colors don't change.

    So is there a way to accomplish this and can I change the RadComboBox and DatePicker too?

    Best regards,
    Ronald
  13. Answer
    Masha
    Admin
    Masha avatar
    355 posts

    Posted 10 Dec 2012 Link to this post

    Hello Ronald,

    There is really such problem with Caret Brush and Selection Color in Expression_Dark theme. You can read more about the problem here. Microsoft is aware of the issue and we hope soon it will be fixed. Unfortunately it is not possible the selection color to be changed in RadControls.

    Sorry for the inconvenience.

    Kind regards,
    Maria
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  14. Ronald
    Ronald avatar
    21 posts
    Member since:
    Dec 2007

    Posted 30 Jan 2013 Link to this post

    Hi Maria,

    sorry for my very late reply... Had to wait until the release before I could try this.
    I added the behavior in a local copy of the ExpressionDarkTextBoxStyle and I now have a white Caret when I select this theme.
    So it is now useable for our customers!

    <Style x:Key="TextBoxStyle" TargetType="TextBox">
     <Setter Property="Background" Value="{StaticResource TextBoxBackground}" />
     <Setter Property="Foreground" Value="{StaticResource ControlForeground_Normal}" />
     <Setter Property="BorderBrush" Value="{StaticResource ControlOuterBorder_Normal}" />
     <Setter Property="FontStyle" Value="Normal" />
     <Setter Property="FontWeight" Value="Normal" />
     <Setter Property="localHelpers:FixCaretBrushBehavior.CaretBrush" Value="White" />
     ...
    </Style>

    Isn't it possible to use this behavior in Telerik's ExpressionDark Theme?

    Again sorry for my late reply and thanks a lot for your help,
    Ronald
  15. Masha
    Admin
    Masha avatar
    355 posts

    Posted 04 Feb 2013 Link to this post

    Hello Ronald,

    At the moment that behavior is not working with RadControls. We will consider including it in our future releases. Excuse us for the inconvenience.

    Regards,
    Maria
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  16. Ronald
    Ronald avatar
    21 posts
    Member since:
    Dec 2007

    Posted 04 Feb 2013 Link to this post

    Thanks Maria,

    I'm happy that we can use the dark theme with the suggested workaround. It would certainly be nice to see this in a future release.

    Kind regards,
    Ronald
Back to Top
DevCraft banner