WPF- ViewModel [英] WPF- ViewModel
问题描述
我目前正在尝试使用ViewModel模式并提出错误。
我在向现有viewmodel类添加新属性时出错。
错误显示为"名称"ViewModel"名称空间"clr-namespace:ViewModels"中不存在。" 但是我可以成功构建我的项目。但无法访问设计视图。我试图清理构建并重建
和 厌倦了创建新项目,但仍然有相同的问题..我不明白为什么这些类型的错误显示。任何人都可以提供解决方案来解决这个问题。它将帮助我前进。非常感谢。
The Error shown as "The name "ViewModel" does not exist in the namespace "clr-namespace:ViewModels"." However i can build my project successfully. But cannot access the design view. I tried to clean the build and rebuild and tired to creating new project but still having the same issue.. i did't understand why these type of error displays. Could anyone give the solutions to solve this problem. it will help me to moving forward. Thanks a lot.
推荐答案
嗨Gowthaman Duraisamy ,
Hi Gowthaman Duraisamy,
根据您的错误消息,您似乎没有在窗口实体中定义xmlns,如下所示:
According to your error message, it seems that you have not define xmlns in your window entity, like this:
<Window
x:Class="MyWpfApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:v="clr-namespace:MyWpfApplication.Views"
xmlns:vm="clr-namespace:MyWpfApplication.ViewModels"
Title="DERP"
Content="{Binding DataContext, RelativeSource={RelativeSource Self}}">
<Window.Resources>
<DataTemplate
DataType="{x:Type vm:MainWindowViewModel}">
<v:MainWindowView />
</DataTemplate>
</Window.Resources>
<Window.DataContext>
<vm:MainWindowViewModel />
</Window.DataContext>
</Window>
如果问题仍然存在,请提供相关代码,以便重现问题。或者通过OneDrive分享一个简单的演示。
if the issue still exist, could you please provide related code, which could reproduce the issue. or share a simple demo via OneDrive.
祝你好运,
张龙
这篇关于WPF- ViewModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!