【发布时间】:2012-03-04 17:11:44
【问题描述】:
我正在创建一个简单的 WPF 应用程序。我有一个函数 OpenFile:
private void OpenFile(string fileName)
{
if(!File.Exists(Helper.GetPath(fileName)))
{
MessageBox.Show("Error opening file");
}
else
{
//Code to handle file opening
}
}
理想情况下这个函数应该出现在哪里?我觉得它应该在.xaml.cs 中,因为它访问了View 部分中的MessageBox。但它也调用了模型中的我的助手。所以我也认为它可以在ViewModel。在View 或ViewModel 中使用它有什么好处?有人可以帮我指点一下吗?
谢谢。
【问题讨论】: