Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法运行基于catel 4的简单应用程序_C#_Mvvm_Catel - Fatal编程技术网

C# 无法运行基于catel 4的简单应用程序

C# 无法运行基于catel 4的简单应用程序,c#,mvvm,catel,C#,Mvvm,Catel,我试图运行一个基于catel 4的简单应用程序,但我甚至没有显示窗口。我没有错误或警告 下面是测试应用程序和应用程序本身的代码 <catel:DataWindow x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

我试图运行一个基于catel 4的简单应用程序,但我甚至没有显示窗口。我没有错误或警告

下面是测试应用程序和应用程序本身的代码

<catel:DataWindow x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:catel="http://catel.codeplex.com"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <CheckBox Content="Check me to continue" IsChecked="{Binding UserAgreedToContinue, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" />
</Grid>

公共部分类主窗口:数据窗口
{
公共主窗口()
:base(DataWindowMode.Custom)
{
初始化组件();
}
}
公共类MainWindowViewModel:ViewModelBase
{
公共重写字符串标题{get{return“Just acknowledge”;}
公共bool用户同意继续
{
获取{返回GetValue(UserAgreedToContinueProperty);}
set{SetValue(UserAgreedToContinueProperty,value);}
}
公共静态只读属性data UserAgreedToContinueProperty=RegisterProperty(“UserAgreedToContinue”,typeof(bool));
}
我做错了什么?为什么连窗户都不打开呢?
启用调试日志侦听器:

    public App()
    {
#if DEBUG
        LogManager.AddDebugListener();
#endif
    }
它会立即向您显示出问题所在:

无法创建视图“WPFAApplication1.MainWindow”的视图模型 断然的。确保自定义IViewModelLocator或注册 手动查看和查看模型

这是因为您没有MVVM中通常使用的名称空间。当然可以,但由于您是初学者,我建议您采取以下措施:

  • 将视图模型移动到WpfApplication1.ViewModels命名空间
  • 将视图移动到WpfApplication1.Views命名空间(xaml和代码隐藏)
  • 将App.xaml中的启动uri更改为“/Views/MainWindow.xaml”
  • 我还强烈建议您阅读

        public App()
        {
    #if DEBUG
            LogManager.AddDebugListener();
    #endif
        }