What the best way to use a custom theme?

4 posts, 0 answers
  1. Giovanni
    Giovanni avatar
    37 posts
    Member since:
    Feb 2011

    Posted 25 Oct 2012 Link to this post

    Hi, I'm trying to build a custom theme to use over all my application.
    I stardet from an existing theme, as suggested, and I've build my custom them as a tssp file.

    I added the tssp to my project and I setted it as application theme:

    ThemeResolutionService.LoadPackageResource("MyProject.MyCustomTheme.tssp")
    ThemeResolutionService.ApplicationThemeName = "MyCustomTheme"

    When I build and I run the application, all the forms and controls appears with my custom theme, and this is very good.
    But at design time, using the visual studio form editor I don't see my theme.
    How can I see my theme even in design time?

    Do I have to load the same theme using a RadThemeManager (from the xml equivalent files) and set the ThemeName property for all controls?
    If yes, which is the utility of using the ApplicationThemeName property?

    Thank you.
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 30 Oct 2012 Link to this post

    Hello Giovanni,

    Thank you for writing.

    In order to load a theme in design time you need to create a component from it. Attached you can find a sample project demonstrating how to do that.

    Let me know if you have any additional questions regarding this matter.
     
    Kind regards,
    Stefan
    the Telerik team
    Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Giovanni
    Giovanni avatar
    37 posts
    Member since:
    Feb 2011

    Posted 31 Oct 2012 Link to this post

    Thank you Stefan,
    I tried your example but I have some troubles.

    First, it works fine in design mode, but it doesn't work at running time (please see attached capture.png file). I simple setted the ThemeName property of the button, as you can see in capture2.png attached file.

    Second, I tried to add a new theme to your ClassLibrary1 project, MyCustomTheme, I added it to the WindowFormsApplication7 but it doesn't appear as value on the ThemeName combo (as you can see in the capture3.png attached file).


    Thank you.

  5. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 02 Nov 2012 Link to this post

    Hello Giovanni,

    It is my omission - I missed to add the code for overriding the ThemeName. Here is the full code for the theme component:
    public class TelerikMetro : RadThemeComponentBase
      {
          static bool loaded = false;
     
          public TelerikMetro()
          {
              ThemeRepository.RegisterTheme(this);
          }
     
          public override void Load()
          {
              if (!loaded || IsDesignMode)
              {
                  loaded = true;
                  Assembly resourceAssembly = typeof(TelerikMetro).Assembly;
                  LoadResource(resourceAssembly, "ClassLibrary1.TelerikMetro.tssp");
              }
          }
     
          public override string ThemeName
          {
              get
              {
                  return "TelerikMetro";
              }
          }
      }

    Let me know how this works for you.
     
    Greetings,
    Stefan
    the Telerik team
    Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
Back to Top