none
XAML Resource Error - The resource "x" could not be resolved. RRS feed

  • Question

  • Hi all,

    I have small issue, I have created a resource file that basicly define which control in my application should provide Validation.ErrorTemplate.

    The error template is actually in another library (called WPFTools).

    So in my application I have created the following ResourceDictionnary.

    The problem is that at design time I get this error (at the bold and underlined line):

    The resource "ErrorTemplate" could not be resolved.

    But at run time, everything works fine, and the template is applied correctly to my controls.

    (please note that the "ErrorTemplate" is a valid key in my resource in the mergeddictionary.

    The error doesn't block my builds but I would love to get rid of it since it doesn't look good.

    Any ideas?

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        xmlns:xceed="http://schemas.xceed.com/wpf/xaml/toolkit">
    
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/WPFTools;component/Resources/ErrorTemplateResource.xaml" />
        </ResourceDictionary.MergedDictionaries>
        
        <!--The error template used for the controls-->
        <Style x:Key="ValidationErrorTemplateStyle" TargetType="{x:Type Control}">
            <Setter Property="Validation.ErrorTemplate" Value="{StaticResource ErrorTemplate}"/>
        </Style>
    
        <!--The style for all TextBox-->
        <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource ValidationErrorTemplateStyle}"/>
    
        <!--The style for all ComboBox-->
        <Style TargetType="{x:Type  ComboBox}" BasedOn="{StaticResource ValidationErrorTemplateStyle}"/>
    </ResourceDictionary>
    
    
    
    

    Wednesday, December 11, 2013 8:36 PM

Answers

  • Hi thanks for the answer, but sadly I cannot do this.

    actually I did it this way in order to reuse this file in the application resources of this program and other programs so it must stay in its own file :


    You could keep it in its own file but you should also add it to the dictionary in App.xaml to make the resource available at design time.

    This means that the merged resource dictionary will be referenced from more than one file but this is required for the designer to work as expected.

    • Marked as answer by SlickRickD Thursday, December 12, 2013 4:23 PM
    Thursday, December 12, 2013 3:06 PM

All replies

  • You could try to also include the dictionary in App.xaml as described on MSDN here: http://msdn.microsoft.com/en-us/library/bb546934(VS.90).aspx#ResourcesatDesignTime

        <Application.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="pack://application:,,,/WPFTools;component/Resources/ErrorTemplateResource.xaml" />
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Application.Resources>
    

    Wednesday, December 11, 2013 10:05 PM
  • Hi thanks for the answer, but sadly I cannot do this.

    actually I did it this way in order to reuse this file in the application resources of this program and other programs so it must stay in its own file :

    Wednesday, December 11, 2013 10:42 PM
  • Hi,

    I encountered this issue in VS 2010. I will clean my solution and rebuild the solution. It will solve this issue. Or restart VS.

    Hope this way can help you.

    Have a nice time!

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 12, 2013 8:33 AM
  • Hi thanks for the answer, but sadly I cannot do this.

    actually I did it this way in order to reuse this file in the application resources of this program and other programs so it must stay in its own file :


    You could keep it in its own file but you should also add it to the dictionary in App.xaml to make the resource available at design time.

    This means that the merged resource dictionary will be referenced from more than one file but this is required for the designer to work as expected.

    • Marked as answer by SlickRickD Thursday, December 12, 2013 4:23 PM
    Thursday, December 12, 2013 3:06 PM
  • Yeah, you're right. It does fix the problem. I thought I would've been able to avoid this since this resource is not really used in this application.

    But it does work :0

    Thursday, December 12, 2013 4:23 PM
  • Try adding xmlns entry mentioned below:

    It worked for me.

    xmlns:sys="clr-namespace:System;assembly=mscorlib"

    Thursday, August 2, 2018 11:09 AM
  • After few hours i found out that problem is Platform Target set to x64.

    After changing it to AnyCPU the resources in design works..
    Thursday, December 5, 2019 8:02 PM