Home > Blockchain >  C# Winforms with custom Telerik theme: embedded resource and ThemeResolutionService.LoadPackageResou
C# Winforms with custom Telerik theme: embedded resource and ThemeResolutionService.LoadPackageResou

Time:12-23

I am using a custom theme and load it as .tssp file in my Program.cs at the moment (which works):

ThemeResolutionService.LoadPackageFile("data\\myThemeName.tssp");

But instead I want to load the .tssp file as embedded resource. Therefore I added the file as resource file under Resources.resx and put the following method in my Program.cs:

ThemeResolutionService.LoadPackageResource("myProject.Properties.Resources.myThemeName");

But the following error occurs:

Specified resource does not exist in the provided assembly.

The path within quotation marks should be correct as the IDE finds it when I remove the quotation marks. I also use different images as embedded resource under the same ressource path which works.

Is this Telerik method bugged or am I doing something wrong?

CodePudding user response:

The ThemeResolutionService class exposes two static methods that allow you to load a theme package:

  • LoadPackageResource: This method loads a theme package file that is contained in the project as an EmbeddedResource. This is the preferable method for loading a theme package since the resource path to the package is not changed when the application is deployed. The path construction is DefaultProjectNamespace.ThemeFolder.ThemePackageFile. The ThemeFolder part should only be used if the package is contained in a folder under the main project directory and if the project programming language is C#. In VB.NET project you do not need to include ThemeFolder part even if the package file is contained in a folder.

    ThemeResolutionService.LoadPackageResource("SamplesCS.CustomTheme.tssp");

enter image description here

enter image description here

        public RadForm1()
    {
        InitializeComponent(); 

        ThemeResolutionService.LoadPackageResource("CustomThemeResourcePackage.Resources.FluentDarkModified.tssp");
        ThemeResolutionService.ApplicationThemeName = "FluentDarkModified";
    }

And the result:

enter image description here

  • LoadPackageFile: This method loads a file from a specified directory on the system. Depending on how the directory is defined (full or relative), the path to the package may change when the application is deployed on another machine.

    ThemeResolutionService.LoadPackageFile(@"C:\CustomTheme.tssp");

  • Related