Silverlight: resource {0} could not be resolved (only at design time)

I created a new silverlight 4 project in VS2010.

My App.xaml file looks like this:

<Application 
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
            x:Class="ZCall.App">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources/Styles.xaml"/>
                <ResourceDictionary Source="Resources/ObjectResourceDictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>                        
        </ResourceDictionary>
    </Application.Resources>
</Application>

xaml sample that generates an error:

<UserControl x:Class="ZCall.View.Control.CDetailsControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"  
    mc:Ignorable="d">

    <Grid x:Name="LayoutRoot" Background="White">
        <toolkit:BusyIndicator x:Name="biCDetails" BusyContent="Busy...">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition Height="10"/>
                    <RowDefinition/>
                    <RowDefinition Height="10"/>
                    <RowDefinition/>
                    <RowDefinition Height="10"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="150"/>
                    <ColumnDefinition Width="10"/>
                    <ColumnDefinition Width="150"/>
                    <ColumnDefinition Width="10"/>
                    <ColumnDefinition Width="170"/>
                </Grid.ColumnDefinitions>

                <StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="5" Orientation="Horizontal">
                    <TextBlock Text="Name:" Style="{StaticResource PatientLabel}"/>
                    <TextBlock x:Name="txtName" Style="{StaticResource PatientData}"/>
                </StackPanel>


            </Grid>
        </toolkit:BusyIndicator>

    </Grid>
</UserControl>

I get errors for both PatientLabel resources and PatientData.

The style.xaml file is located in the Resources folder in the project root directory.

My problem is that during development, none of my styles defined in styles.xaml is recognized, and I get an error "Resource cannot be resolved" for each style used, and at runtime, all styles are allowed and displayed as it should be.

Any suggestions?

Thanks in advance, kruvi

+3
source share
8 answers

App.xaml ApplicationDefinition App.xaml .

+5

, . xaml , :

<ResourceDictionary 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/Assembly;component/Themes/PageStyles.xaml"/>
        <ResourceDictionary Source="/Assembly;component/Themes/CommonStyles.xaml"/>
        <ResourceDictionary Source="/Assembly;component/Themes/PageStyles.Dark.xaml"/>
        <ResourceDictionary Source="/Assembly;component/Themes/CommonStyles.Dark.xaml"/>
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

App.xaml :

<Application 
    x:Class="Assembly.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"       
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">

    <!--Application Resources-->
    <Application.Resources>
        <ResourceDictionary Source="Resources/MainResource.xaml" />
    </Application.Resources>

    <Application.ApplicationLifetimeObjects>
        <!--Required object that handles lifetime events for the application-->
        <shell:PhoneApplicationService 
            Launching="Application_Launching" Closing="Application_Closing" 
            Activated="Application_Activated" Deactivated="Application_Deactivated"/>
    </Application.ApplicationLifetimeObjects>

</Application>

, .

+1

, MVVM-Light. , , app.xaml .

app.xaml. Application.Resources. Visual Studios.

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Assets/Styles.xaml"/> 
            <ResourceDictionary Source="Skins/MainSkin.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
    <!--Global View Model Locator-->
    <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
</Application.Resources>

. , ResourceDictionary. resourceDictionary, .

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Assets/Styles.xaml"/>
            <ResourceDictionary Source="Skins/MainSkin.xaml" />                
        </ResourceDictionary.MergedDictionaries>
        <!--Global View Model Locator-->
        <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
    </ResourceDictionary>        
</Application.Resources>
+1

Microsoft.Practices.Unity.Silverlight . , .

0

WPF. projecst App.xaml, , , - . , VisualStudio: , , <SubType>Designer</SubType>:

<EmbeddedResource Include="Properties\Resources.resx">
  <Generator>PublicResXFileCodeGenerator</Generator>
  <SubType>Designer</SubType>
  <LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>

<SubType>, VS .

0

, App.xaml App.xaml

, App.xaml Properties :

  • : ApplicationDefinition
  • :
  • : MSBuild: MSBuild: MarkupCompilePass1
  • : []
  • : App.xaml
0

. ResourceDictionary UserControl, , .xaml.cs UserControl, :

this.Resources=new ResourceDictionary();

. , ResourceDictionary (, App.xaml).

, .

0

- , , (, app.xaml) , , .

We had this problem caused by two minor errors in the style file. As soon as we corrected these errors and performed a complete overhaul of the entire solution, all styles were correctly resolved throughout the entire solution.

So, look at the file containing the resource and correct everything that the designer believes is an error (the blue line is squiggly under at the bottom), and then do a complete rebuild.

0
source

Source: https://habr.com/ru/post/1792154/


All Articles