是的。那么你可以在视图模型一个模型对象,并把它保存在一个文本文件中的文本(或任何你想你的应用程序做的)
class ViewModelDefault : INotifyPropertyChanged
{
// Bound to your textbox
public string TextboxProperty { get; set;}
// Instantiate modellayer in viewmodel
private ModelClass _modelClass = new ModelClass();
// RelayCommand property -> bound to button on viewmodel
// Will execute method "ExecuteCommand" that contains a call to a method in the ModelClass
public ICommand ExecuteModelMethod
{
get {
RelayCommand relayCommand = new RelayCommand(ExecuteCommand);
return relayCommand;
}
}
// Method that the RelayCommand will execute.
private void ExecuteCommand()
{
_modelClass.SaveTextInTextfile(TextboxProperty);
}
...
}
在上面的代码我做的怎么样,这可能是一个例子使用RelayCommand完成。
RelayCommand是一个使用Action和Func等委托的类。这意味着你可以传递一个方法到RelayCommand对象中并让它执行它。
RelayCommand允许您通过代理将视图层中的UI控件绑定到基本方法。
如果您想进一步研究该主题,请阅读代表。 Delegates (C# Programming Guide)
谢谢。你的回答帮助了我很多。 – hoxplus