This is a migrated thread and some comments may be shown as answers.

Designer exception in nested UserControl with telerik control

8 Answers 342 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Hillin
Top achievements
Rank 1
Hillin asked on 05 Nov 2018, 06:17 PM

Hi,

I've been dealing with this problem for days without being able to find a solution. Here is the thing, if I put a Telerik control, say RadTabControl, in a UserControl ("UserControl A"), I can edit it with the VS designer without any problem. If I put UserControl A into another UserControl ("UserControl B"), I can see and edit UserControl B as long as I keep the designer window open. If I close the designer window and open it again, the designer would not load, and throws an exception complaining that it cannot create an instance of UserControl B. The exception hierarchy looks like this:

Exception: Cannot create an instance of "UserControl B"

 - TargetInvocationException: Exception has been thrown by the target of an invocation.

 -- XamlParseException: 'Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number '19' and line position '20'.

 --- Exception: Cannot find resource named 'Telerik.Windows.Controls.RadTabItem'. Resource names are case sensitive.

 

Please help me! Thanks in advance.

8 Answers, 1 is accepted

Sort by
0
Hillin
Top achievements
Rank 1
answered on 08 Nov 2018, 03:17 AM

OK, I figured it out that you have to add the corresponded xaml reference in the UserControl's Resources in order to allow the designer to work properly. E.g. if a RadTabControl is employed in a UserControl, the following line has to be added into the MergedDictionaries collection of UserControl.Resources:

<ResourceDictionary Source="/{your_theme};component/Themes/Telerik.Windows.Controls.Navigation.xaml" />

However this is not required in the runtime. Could be a designer bug (it seems sometimes the designer is unable to load resources defined in App.xaml correctly).

0
Dinko | Tech Support Engineer
Telerik team
answered on 08 Nov 2018, 11:27 AM
Hi Hillin,

Thank you for the provided solution for this type of exception. Still, I couldn't reproduce it on my side. I think this issue is related to VS designer. My understanding is that you are referencing NoXAML binaries. Correct me if I am wrong. I have tested it on my side with VS 2017 (version 15.8.7) and VS 2015 (14.0.25431.01 Update 3) and no exception appears. Can you share the version of VS which you are using on your side?

Regards,
Dinko
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Hillin
Top achievements
Rank 1
answered on 10 Nov 2018, 02:45 PM

Hi Dinko,

I'm using Visual Studio Enterprise 2017 (v15.8.4), with Telerik WPF 2018.1.

0
Dinko | Tech Support Engineer
Telerik team
answered on 14 Nov 2018, 01:46 PM
Hi Hillin,

Thank you for the provided additional information. Still, I wasn't able to reproduce it on my side. As I suspect that this issue may be caused by Visual Studio's shadow cache, could you please try clearing that if you have not done so already? It is located at %LOCALAPPDATA%\Microsoft\VisualStudio\14.0\Designer\ShadowCache. After that, you can clean and rebuild the project.

Can you also download the latest version of our controls and check on your side if this exceptions still appears? I am also attaching the sample project which I used to test your scenario. You can take a look and let me know if the structure of the example is the correct one.

Regards,
Dinko
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Hillin
Top achievements
Rank 1
answered on 19 Nov 2018, 08:00 AM

Thanks Dinko.

It seems I've missed an important detail in my description. In UserControl A, "StaticResource {x:Type telerik:RadTabItem}" has to be referenced. E.g.:

        <telerik:RadTabControl >

            <telerik:RadTabControl.ItemContainerStyle>
                <Style TargetType="telerik:RadTabItem"
                       BasedOn="{StaticResource {x:Type telerik:RadTabItem}}">
                    <Setter Property="Padding" Value="8" />
                </Style>
            </telerik:RadTabControl.ItemContainerStyle>
            <telerik:RadTabItem Header="Tab 1"/>
            <telerik:RadTabItem Header="Tab 2" Height="35" Width="100"/>
            <telerik:RadTabItem Header="Tab 3" Width="115"/>
        </telerik:RadTabControl>

 

This will reproduce the issue with the project you provided.

0
Dinko | Tech Support Engineer
Telerik team
answered on 21 Nov 2018, 12:21 PM
Hi Hillin,

Thank you for the provided code snippet.

I manage to reproduce this exception. Looking at the provided code snippet you have based the Style on the Type RadTabItem. It seems that this is the problem. Basically, the pattern of the name of the style of our controls contains the name of the control plus Style string at the end. For example, for the RadTabItem will be RadTabItemStyle. It seems that in this particular scenario the designer could not find such resource and exception appear. What you can do is to based on the custom style to the name directly. 
<telerik:RadTabControl >
    <telerik:RadTabControl.ItemContainerStyle>
        <Style TargetType="telerik:RadTabItem" BasedOn="{StaticResource RadTabItemStyle }">
            <Setter Property="Padding" Value="8" />
        </Style>
    </telerik:RadTabControl.ItemContainerStyle>
    <telerik:RadTabItem Header="Tab 1"/>
    <telerik:RadTabItem Header="Tab 2" Height="35" Width="100"/>
    <telerik:RadTabItem Header="Tab 3" Width="115"/>
</telerik:RadTabControl>

Regards,
Dinko
Progress Telerik
Get quickly and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Hillin
Top achievements
Rank 1
answered on 21 Nov 2018, 12:53 PM

Thanks a lot Dinko! This worked like a charm!

The only exception in my project is RadDatePicker, the static resource RadDatePickerStyle cannot be found, but RadDateTimePickerStyle did the job very well.

0
Dinko | Tech Support Engineer
Telerik team
answered on 22 Nov 2018, 01:49 PM
Hello Hillin,

That is great that the provided solution works for you. Indeed, that there is no style with x:Key=" RadDatePickerStyle ". The default style of the RadDatePickerRadTimePicker, and RadDateTimePicker is a RadDateTimePickerStyle.

Regards,
Dinko
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
General Discussions
Asked by
Hillin
Top achievements
Rank 1
Answers by
Hillin
Top achievements
Rank 1
Dinko | Tech Support Engineer
Telerik team
Share this question
or