如何在 MVVM 模式 silverlight 中通过功能 ok 和取消来关闭 OpenFileDialog?
我看到了很多关于这个主题的不同信息,但没有任何帮助我。
- 你觉得怎么样?也许使用比 MVVM 和 OpenFileDialog 更简单的模式更好?
- 我有 2 个功能“确定”和“取消”。每个都有
(this.DialogResult = true)
或(this.DialogResult = false)
。我必须以 MVVM 模式制作它。我正在使用value -> (bool cls = true)
现在将其绑定到DialogResult = {Binding cls}
并在不同的函数中更改此属性,但它不起作用。我得到一些例外。
你知道如何通过关闭 OpenFileDialog 来解决这个问题吗?
I saw a lot of different information on this theme but nothing helped me.
- How do u think? Probably better use a simpler pattern than MVVM with OpenFileDialog?
- I have 2 functions Ok and Cancel. Each one has
(this.DialogResult = true)
or(this.DialogResult = false)
. I must make it in MVVM pattern. I am usingvalue -> (bool cls = true)
right now and bind it toDialogResult = {Binding cls}
and change this property in different functions but it doesn't work. I get some exception.
Do you know how I can solve this problem with closing OpenFileDialog
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里的 create as 方法可能会让您符合您正在寻找的内容
create as method here is something that may get you along the lines of what you are looking for
如果无论状态如何,确定和取消按钮始终处于启用状态,那么我认为将它们合并到 MVVM 设计模式中没有什么价值。我不使用 silverlight,但假设它与 WPF 类似,您可以在“属性”窗格中检查“取消”按钮的 IsCancel 属性,当您单击该按钮时,它将自动关闭对话框并设置 DialogResult=false。对于您的“确定”按钮,
在后面的代码中添加像这样的简单内容。
我知道有些纯粹主义者不希望后面的代码中包含任何内容,但对我来说,更简单、更易于维护的代码更好(也是实现 MVVM 的目的)。现在,如果我的“确定”和“取消”按钮仅在某些模型条件下启用,我可能会将它们设置为与 ModelView 交互。
If you're OK and CANCEL buttons are always enabled regardless of state, I see little value in incorporating them in the MVVM design pattern. I don't do silverlight but assuming it's similar to WPF, you can check the IsCancel property in the Properties pane for your Cancel button and that will automatically close the dialog and set DialogResult=false when you click the button. For your OK button add something simple like this
Then in the code behind.
I know some purists want nothing in the code behind but to me, simpler more maintainable code is better (and the point of implementing MVVM). Now if my OK and Cancel buttons only enabled under certain model conditions I would probably set them up to interact with the ModelView.