I'm working on converting my project to use Implicit Styles. I've followed the Documentation to a T. I'm using NoXAML binaries, I've copied the entire set of theme XAML files into my project, merged them all in the App.xaml file, etc.
Everything I ask to use an implicit theme winds up throwing an error that says "Key cannot be null". Sometimes the entire designer is replaced with a window that says the same and gives a StackTrace. I've attached screenshots of both.
Can anyone give me some guidance here? Telerik doesn't release crappy broken components, so I'm assuming that I'm missing something easy.
Humble me please. :)
10 Answers, 1 is accepted
Thank you for contacting us on this issue.
One way to use ImplicitStyles is to copy and manage the .xaml files on their own in your project or to refer them from the theme assembly with all the needed components (here is just a sample prieview):
<
Application.Resources
>
<
ResourceDictionary
>
<
ResourceDictionary.MergedDictionaries
>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Office_Black;component/Themes/System.Windows.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.Navigation.xaml"
/>
</
ResourceDictionary.MergedDictionaries
>
</
ResourceDictionary
>
</
Application.Resources
>
I am mentioning that because you might have missed a reference somewhere from the needed styles (some controls depend on styles from other groups - e.g. RadToolBar needs all the Buttons' and RadButtons styles etc).
Furthermore, since you have made sure you are using all noXAML binaries for all the controls, you can try Cleaning the solution, then manually cleaning the contents of the bin and obj folders of the project(s) and Rebuilding them and restart the VisualStudio.
If the error message persists and you are not receiving an exception when you run the project - you might need to clean the cache of the Designer. It caches the needed assemblies for quicker loading but in cases when they are switched, it might not replace them properly.
You can try manually cleaning the ShadowCache folder - which is the cache for the assemblies for the designer. It is normally situated at:
C:\Users\<user>\AppData\Local\Microsoft\VisualStudio\<version>\Designer\ShadowCache
If you do that, you would need to close any instances of VisualStudio. It can be a of a great size, so cleaning it might take some time. On the next start, the Designer will take time to load, but it should work properly.
However, if the exception persists, please do not hesitate to contact us again and if it possible, attach a sample project where the behavior manifests so we can examine it.
Regards,
Martin
Telerik by Progress
Hi Martin,
Thanks for the response. I am completely baffled by what is going on. I created a blank project and everything works just fine. So I started copying all of my existing project over to the one to try and see what would cause it to break. It never broke. So then I figured it must be some project configuration issue. So I opened each project file in notepad and compared line by line and everything matches.
No matter what I do, I can't get the original project to work.
My OCD isn't letting me drop this even though the new project works (I'm concerned the new project will work temporarily and then I'll do something to cause the same error again). Do you have any advice as to how I can debug this? I've attached the VS debugger to the XAML Designer and found that whenever I modify the Style attribute of one of the controls in question, a System.ArgumentNullException is thrown. The null value causing the exception is the resourceKey for the FrameworkElement (which is a TextBox in this case).
I hope this helps.
Hi Martin,
One other thing that may help you answer my question is that if use the Theme Assembly, everything works just fine. So it must be something to do with the actual XAML files. Does it matter which order I merge them in?
Sorry to be a pain.
Dave
My gosh I'm sorry to spam this thread like this. I don't get the "key cannot be null" message. But the project is unable to resolve the stock styles contained within the Theme Assembly (e.g. The resource "TextBoxStyle" could not be resolved.). Here is my App.xaml file. I've referenced the Theme Assembly. Also, this only happens in the Designer. When I run the application everything looks just fine.
<
Application
x:Class
=
"PatchPro.Dispatch.App"
xmlns:local
=
"clr-namespace:PatchPro.Dispatch"
StartupUri
=
"Views/DispatchDockingView.xaml"
>
<
Application.Resources
>
<
ResourceDictionary
>
<
ResourceDictionary.MergedDictionaries
>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Windows8;component/Themes/System.Windows.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Data.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Docking.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.GridView.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Input.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Navigation.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Spreadsheet.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.xaml"
/>
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Documents.xaml"
/>
<
ResourceDictionary
Source
=
"/Assets/Styles/UniversalStyles.xaml"
/>
</
ResourceDictionary.MergedDictionaries
>
</
ResourceDictionary
>
</
Application.Resources
>
</
Application
>
It could be the order of merging as some styles depend on other styles from more basic assemblies. I can suggest you move the Controls.xaml dictionary in the beginning after System.Windows.xaml. It might solve the issue.
Normally cleaning the cache in obj and bin folders of the project, restarting VS and rebuilding should sort that issue if it has something to do with wrong cached assemblies.
I cannot reproduce this for now, so could I ask you if the issue still persists to either list the controls you are using in your project or send a sample code or project where this error occurs, so we can investigate it further.
Regards,
Martin
Telerik by Progress
Solved...sort of.
After hours of looking for what was causing that "Key cannot be null" exception, I decided to upgrade my project from .NET 4.5.2 to 4.6.1. Whatever was going on resolved immediately which is bizarre.
Just prior to upgrading I was in the process of debugging the Designer with the .NET Framework source code. From what I could gather something was going on within System.Windows.xaml and it had to do with a ScrollViewer.
No idea if that's of any use to you guys at Telerik.
Thanks for trying to help though, much appreciated.
It is true that the threads here are public. You can open a Support thread, which will be private and you can attach a project there.
It could be a problem with cached assemblies either in the project or in the designer cache (the Shadow Cache folder), since the problem is resolved by changing the .NET version.
Regards,
Martin
Telerik by Progress
I don't think it had to do with caching as I cleared the bin/obj folders as well as the ShadowCache folder multiple times. But it is awfully suspicious that changing the version fixed it.
Anyhow, thanks for the suggestions.
Thank you for your cooperation. I am as well unaware of the possible cause of the problem.
I am pleased that the issue is resolved on your side. I will look into that.
If you feel the need, you can open a support thread to attach sample project where the issue is isolated.
Please do not hesitate to contact us further, if you are facing problems with the usage of our controls.
Regards,
Martin
Telerik by Progress