monty.py
monty.py

Reputation: 2789

xaml x:static cannot find namespace

I have a resourcefile (named StringResources) in the Project xyz.mvvm.res (res is a folder).

<Window x:Class="xyz.MVVM.Views.ReadAllReportWindow"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"
             xmlns:resources="clr-namespace:xyz.MVVM.res;assembly=xyz.MVVM"
             Title="{x:Static resources:StringResources.Window_Title}" 
             WindowStartupLocation="CenterScreen">
    <Grid>

    </Grid>
</Window>

I get an error

"The name "StringResources" is not available in the Namespace "clr-namespace:xyz.MVVM.res;assembly=xyz.MVVM".

The resourcefile is set to public! I´am despairing..

Edit: StringResources.Designer.cs:

namespace xyz.MVVM.res {
    using System;

    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    public class StringResources {

        private static global::System.Resources.ResourceManager resourceMan;

        private static global::System.Globalization.CultureInfo resourceCulture;

        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        internal StringResources() {
        }

        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        public static global::System.Resources.ResourceManager ResourceManager {
            get {
                if (object.ReferenceEquals(resourceMan, null)) {
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TimeRecordReader.MVVM.res.StringResources", typeof(StringResources).Assembly);
                    resourceMan = temp;
                }
                return resourceMan;
            }
        }

        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        public static global::System.Globalization.CultureInfo Culture {
            get {
                return resourceCulture;
            }
            set {
                resourceCulture = value;
            }
        }

        public static string Window_Title {
            get {
                return ResourceManager.GetString("Window_Title", resourceCulture);
            }
        }
    }
}

Upvotes: 1

Views: 1907

Answers (2)

keymusicman
keymusicman

Reputation: 1291

<Window x:Class="xyz.MVVM.Views.ReadAllReportWindow"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"
             xmlns:resources="clr-namespace:xyz.MVVM.res;assembly=xyz.MVVM"
             WindowStartupLocation="CenterScreen">

    <Window.Title>
        <Binding Source="{x:Static resources:StringResources.Window_Title}"/>
    </Window.Title>

    <Grid>

    </Grid>
</Window>

Upvotes: 0

Ryan Searle
Ryan Searle

Reputation: 1627

I had a similar issue, it turns out I had to delete the cache.

-Save and close MS Visual Studio

-Go to %LOCALAPPDATA%\Microsoft\VisualStudio\14.0\Designer\ShadowCache\

-Delete contents

-Open MS Visual Studio

Note: Put your Version number instead of 14.0

Upvotes: 2

Related Questions