I want to use Telerik implicit styles because this seems to be the favorite technique to use with Telerik controls.
So I use the Telerik noxaml dll's in my project.
I have made a separate class library in which I have included the Telerik resources (the theme resource files). These resources are merged at startup (in the Application class) using code like
Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(
new
ResourceDictionary
{
Source =
new
Uri(
"/libraryDll;component/Themes/System.Windows.xaml"
, UriKind.Relative)
});
When running the application all works fine and the radwindow is displayed and styled correctly.
However, at design time I don't see anything. This is (of course) because at design time the xaml resources are not available (loaded).
How do I fix this problem so I can see the telerik controls at design time? If you can't see the controls you can't design a window can you?
Regards,
Peter
10 Answers, 1 is accepted
You could merge the same resource dictionaries in Application.Resources of App.xaml file in order to see the controls in the designer. Afterwards you can change the theme in code behind without a problem whenever needed:
<
Application.Resources
>
<
ResourceDictionary
>
<
ResourceDictionary.MergedDictionaries
>
<
ResourceDictionary
Source
=
"/libraryDll;component/Themes/System.Windows.xaml"
/>
<
ResourceDictionary
Source
=
"/libraryDll;component/Themes/Telerik.Windows.Controls.xaml"
/>
<
ResourceDictionary
Source
=
"/libraryDll;component/Themes/Telerik.Windows.Controls.Input.xaml"
/>
<
ResourceDictionary
Source
=
"/libraryDll;component/Themes/Telerik.Windows.Controls.Navigation.xaml"
/>
</
ResourceDictionary.MergedDictionaries
>
</
ResourceDictionary
>
</
Application.Resources
>
However if this is not helping, I would like to ask you to share some more details regarding the setup of the project. If you an open up support ticket with a sample project attached, we will be glad to check it on our side and provide you with a solution.
I'm looking forward to hearing from you.
Regards,
Kalin
Telerik
Hi Kalin,
This can work when I have an App available. But when developing a separate library (assembly/dll) in which I want to create user controls which use telerik controls, I don't have an App.xaml available (because it's a class library and not a wpf app).
This means I am forced to always include a wpf project when I want to develop a class library that contains telerik controls and uses implicit styles? That's not very convenient.
Regards,
Peter
I'm sorry for misunderstanding. What I can suggest you would be to check the attached sample project that demonstrates how can use no xaml binaries in separate ControlLibrary project that don't have App.xaml and still have designer working. Basically the project uses approach similar to this one for embedding the Telerik assemblies in the control library. It includes adding the assemblies as embedded resources, a static TelerikThemeUtilities class and some AssemblyResolve work. This pretty much takes care of embedding the assemblies. When extracting the project just add the referenced binaries to the lib folder of the ControlLibrary project and let me know if
Hope this will work for you.
Regards,
Kalin
Telerik
Hi Kalin,
Thanks for the sample. It looks promising and I think it will do the trick. Adding one line (local:TelerikThemeUtilities.DesignTime="True") to each control seems doable.
I will investigate this further and let you know.
Regards,
Peter
Please check it and let us know if you have any further questions or concerns.
Regards,
Kalin
Telerik
Hi Kalin,
Your suggested solution seems to work very well. Thanks :)
Regards,
Peter
I'm glad the suggestion helped. If you have any other questions, let us know.
Regards,
Kalin
Telerik
Hello,
I know, that this is an old thread. But this is the only one describing my situation.
I'm using the described solution with the static class TelerikThemeUtilities since some years without trouble.
Now I have to make some modifications on that project and have the problem that it no longer works on the new system (Windows 10 with VS 2019).
I'm getting the message:
"Object reference not set to an instance of an object"
on the row:
local:TelerikThemeUtilities.DesignTime="True"
I copied the whole project to an other system and it runs there without problems. All the libs are added to the project. After spending the wohle day I was not able to detect the difference on both systems. One was that the older system runs VS 2017, but installing VS 2017 on the new system didn't help.
Any ideas?
Sometimes it helps to post an issue...
Just after posting it I renewed all Telerik references. Seems this has resolved the issue.
Hi Raul,
We are happy to hear that your question has been resolved, and thank you for sharing the solution for it. If you have any other questions, you can open a new forum thread with your questions posted, and we will be happy to help.
Regards,
Dinko
Progress Telerik