When creating custom skins, there are two parts that you need to do:
- Declare all the resources you are going to use;
- Register the skins.
If you are not familiar with embedded resources and / or web resources, I suggest that you start with the following articles:
- Article on embedded resources as a general -- http://www.codeproject.com/Articles/3089/Understanding-Embedded-Resources-in-Visual-Studio
- Article on web resources -- http://www.codeproject.com/Articles/12997/WebResource-ASP-NET-2-0-explained
Declaring resources
Now that we are on the same page for web resources, let's begin.
As noted in the articles a fully qualified resource name is DefaultNameSpace.[Path.To.File.].FileName with path to file being optional e.g. you can place all your files in the root of your project.
The default namespace of your skin assembly project is available from the right click -> properties menu.
The folder path, though optional, is nice to have, as it helps dealing with multiple skins in a single assembly. Assuming that your skin name is "TelerikYouthful", then you should have a folder named "TelerikYouthful" in the root of your project.
In it, you must have a file named "Window.TelerikYouthful.css". When you add the file, make sure you set the proper build type: right click -> properties, set build type to Embedded Resource.
After having those two set up, it's time to declare the resource. Again, you can use a single file, but I prefer using separate. In the root of your project, create a file RadWindow.Skins.cs.
In it add the following lines:
using System.Web.UI;
#region TelerikYouthful
[assembly: WebResource("CustomSkinAssembly.TelerikYouthful.Window.TelerikYouthful.css", "text/css", PerformSubstitution = true)]
#endregion
The using is needed so you don't write System.Web.UI.WebResource every time. Then comes the fully qualified resource name: my default namespace is CustomSkinAssembly; my path is TelerikYouthful, file name is Window.TelerikYouthful.css.
The type string is obvious.
Perform substitution is needed so you could reference web resources inside the CSS file.
You can build your project now and check the output DLL with a tool like Reflector, JustDecompile, DotPeek etc. to check if the file is indeed embedded.
Registering a skin
Next you need to register the skin. To do so, in your default namespace you need to add the class of the control you want to skin and to annotate that class with an EmbeddedSkin attribute e.g.:
using System.Web.UI;
using Telerik.Web;
#region TelerikYouthful
[assembly: WebResource("CustomSkinAssembly.TelerikYouthful.Window.TelerikYouthful.css", "text/css", PerformSubstitution = true)]
#endregion
namespace CustomSkinAssembly
{
[EmbeddedSkin("Window", "TelerikYouthful", typeof(RadWindow))]
public class RadWindow
{
}
}
Note: I've added a using for Telerik.Web, so we do not use Telerik.Web.EmbeddedSkin all the time.
Now you can build the project and you should be able to use the skin.