繁体   English   中英

MVVM使用ICommand保存在数据库中

[英]MVVM Saving in database using ICommand

我有一个对话框,单击一些保存按钮即可获取一些基本信息,以将这些信息保存到数据库中。 这些基本信息将通过绑定存储在ViewModel中。 我通过实体框架和DataContext处理数据库。

private Command.MonitoringTaskCommand objSaveButtonCommand =
    new Command.MonitoringTaskCommand(
        new Action<DataModel.MonitoringTask>(x => {
            DataModel.MonitorContext context = new DataModel.MonitorContext();
            context.MonitoringTasks.Add(x);
            context.SaveChanges();
        }),
        new Func<bool>(() => {
            Debug.WriteLine("Todo: Validate data... ");
            return true;
        }));

我坚持执行保存。

  • 如何将数据传递给命令?

我知道XAML级别上有CommandParameter,但是数据存储在ViewModel中,并且可以不同于XAML级别上的那个。

数据从命令绑定传递过来,因此在绑定位置使用CommandParameter绑定对象

查看本教程

http://www.c-sharpcorner.com/UploadFile/e06010/wpf-icommand-in-mvvm/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM