现在这是一个真正奇怪的错误.我正在研究WPF应用程序并关注MVVM.在我的MainWindow中,我正在设置视图和查看模型,我得到了这个奇怪的错误.虽然它构建良好,应用程序运行正常,但为什么我收到此错误.
我也跟着一些类似但没有找到合适的答案.我试图重新启动visual studio并清理和重建,但我仍然面临这个错误.
所以这是代码.
<Window x:Class="MyProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:v="clr-namespace:MyProject.Views"
xmlns:vm="clr-namespace:MyProject.ViewModels"
xmlns:p="clr-namespace:MyProject.Properties"
Title="{x:Static p:Resources.Title}" Height="400" Width="750" MinHeight="400" MinWidth="750">
<Window.Resources>
<DataTemplate DataType="{x:Type vm:MainPageViewModel}">
<v:MainPageView/>
</DataTemplate>
</Window.Resources>
Error 1 The name "MainPageViewModel" does not exist in the namespace "clr-namespace:MyProject.ViewModels".
Run Code Online (Sandbox Code Playgroud)
这是我的ViewModel
namespace MyProject.ViewModels
{
public class MainPageViewModel : PropertyChangedBase
{
public MainPageViewModel()
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
那么什么是真正的错误.我顺便使用Visual Studio 2012.
更新: 我的视图模型和视图位于同一个项目中.我没有参考任何其他项目.并且MyProject.ViewModels.MainPageViewModel存在.
每当我尝试打开位于UNC共享上的解决方案时,我都会看到此对话框:

我尝试过使用caspol.exeHanselman在这里谈到的实用程序,但它似乎不起作用.至少不适用于在Visual Studio 2012中运行的.Net 4项目.使用相同的参数运行.NET 4版本的caspol我收到此消息:
WARNING: The .NET Framework does not apply CAS policy by default. Any settings
shown or modified by CasPol will only affect applications that opt into using
CAS policy.
Please see http://go.microsoft.com/fwlink/?LinkId=131738 for more information.
Run Code Online (Sandbox Code Playgroud)
我遵循了这个链接但似乎对我没有任何意义.
为了给出我正在做的事情的一些背景,我在我的Mac上运行Windows 7作为VM(通过VirtualBox)运行.我在我的mac上设置了SMB网络共享,我可以从我的VM成功连接.但是,尝试加载解决方案一直给我这个错误.我知道我可以"取消选中框"并加载所有内容,但我想知道如何完全信任该位置.
我有一个项目,名为“完美”。VS 2012 Ultimate,全部更新。
xmlns:Properties="clr-namespace:Perfect.Properties"我在标题中有一个窗口
我不断收到错误:
The name "Settings" does not exist in the namespace "clr-namespace:Perfect.Properties".
Run Code Online (Sandbox Code Playgroud)
项目编译、构建并运行良好。我的视觉工作室到底是怎么回事?
我得到了另一个解决方案,我只是从中复制了代码,那里没有这样的错误。
UPD:还有其他命名空间问题,例如它无法在我自己的命名空间中找到我的自定义组合框项目,delcared likexmlns:local="clr-namespace:Perfect.Misc"和used <local:VoidComboItem exchange="All available" />。类存在并在运行时工作,但设计编辑器根本不工作,因此我必须使用 XAML 并运行应用程序才能查看更改。