【发布时间】:2019-06-17 13:35:48
【问题描述】:
我正在尝试通过
在 XAML 文件中设置我的数据上下文<Window x:Class="LocationScout.SettingsDeleteWindow"
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:ViewModel="clr-namespace:LocationScout.ViewModel"
mc:Ignorable="d"
Title="Delete" Height="315" Width="350"
WindowStartupLocation="CenterScreen">
<Window.DataContext>
<ViewModel:SettingsDeleteDisplayItem/>
</Window.DataContext>
但是,XAML 编辑器显示错误“名称“SettingsDeleteDisplayItem”在命名空间“clr-namespace:LocationScout.ViewModel”中不存在。
视图模型类对我来说看起来不错:
namespace LocationScout.ViewModel
{
public class SettingsDeleteDisplayItem : BaseObservableObject
{
private long _countryAreaCountToDelete;
public long CountryAreaCountToDelete
{
get => _countryAreaCountToDelete;
set
{
_countryAreaCountToDelete = value;
OnPropertyChanged();
}
}
}
}
构建解决方案工作正常,没有错误。任何想法?非常感谢。
【问题讨论】:
-
设计师因误报错误而享有(当之无愧的)可怕声誉。如果你的程序运行,你只需要忽略它。
-
哦。这是在设计师?重建你的项目。如果这不起作用,请重新启动 Visual Studio 并重建您的项目。如果做不到这一点,请尝试将 ViewModel 更改为小写,如
xmlns:viewModel。 -
@RobertHarvey - 重建没有帮助,但我改为小写并重新启动 Visual Studio - 现在它可以工作了。非常感谢。真的是一个但在设计师...
-
这可能是一个问题的原因是因为
ViewModel(大写)出现在您的命名空间声明中。 -
我觉得这听起来很合理......
标签: c# wpf xaml namespaces datacontext