Xaml x:static找不到命名空间
本文关键字:找不到 命名空间 static Xaml | 更新日期: 2023-09-27 18:07:21
我在项目xyz.mvvm.res
中有一个资源文件(名为StringResources
)(res是一个文件夹).
<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>
我得到一个错误
"名称StringResources在命名空间中不可用"clr-namespace: xyz.MVVM.res;装配= xyz.MVVM"。
资源文件被设置为public!我´绝望. .
编辑: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);
}
}
}
}
我有一个类似的问题,结果我不得不删除缓存。
-保存并关闭MS Visual Studio
-转到%LOCALAPPDATA%'Microsoft'VisualStudio'14.0'Designer'ShadowCache'
删除内容-打开MS Visual Studio
注意:用版本号代替14.0
<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>