Designer exception in nested UserControl with telerik control

9 posts, 0 answers
  1. Hillin
    Hillin avatar
    21 posts
    Member since:
    Sep 2018

    Posted 05 Nov 2018 Link to this post

    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.

  2. Hillin
    Hillin avatar
    21 posts
    Member since:
    Sep 2018

    Posted 07 Nov 2018 Link to this post

    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).

  3. Dinko
    Admin
    Dinko avatar
    1128 posts

    Posted 08 Nov 2018 Link to this post

    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.
  4. Hillin
    Hillin avatar
    21 posts
    Member since:
    Sep 2018

    Posted 10 Nov 2018 Link to this post

    Hi Dinko,

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

  5. Dinko
    Admin
    Dinko avatar
    1128 posts

    Posted 14 Nov 2018 Link to this post

    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.
  6. Hillin
    Hillin avatar
    21 posts
    Member since:
    Sep 2018

    Posted 19 Nov 2018 in reply to Dinko Link to this post

    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.

  7. Dinko
    Admin
    Dinko avatar
    1128 posts

    Posted 21 Nov 2018 Link to this post

    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 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.
  8. Hillin
    Hillin avatar
    21 posts
    Member since:
    Sep 2018

    Posted 21 Nov 2018 in reply to Dinko Link to this post

    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.

  9. Dinko
    Admin
    Dinko avatar
    1128 posts

    Posted 22 Nov 2018 Link to this post

    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.
Back to Top