5
关于MVVM中显示对话框窗口的几种好方法存在很多问题。但我看到Gjallarhorn看起来不同。用Gjallarhorn显示对话窗口的好方法是什么?
我必须显示几个对话框,例如每个对话框有一个动作。
type Action =
|Show
|Open
|Input
|Change
|Statistic
窗口
module Views
open FsXaml
...
type StatisticWindow = XAML<"StatWindow.xaml">
type InputWindow = XAML<"InputWindow.xaml">
...
方式的夫妇,我表现出来
let showDialog (context:BindingSource) (view : System.Windows.Window) =
view.DataContext <- context
view.ShowDialog() |> ignore
let getViewByAction =
function
|Statistic -> Views.StatisticWindow() :> System.Windows.Window
|Input -> Views.InputWindow() :> System.Windows.Window
| ...
let getContextByAction model =
function
| Statistic -> statContext model
| Input -> inputContext model
| ...
let performAction model action =
let context = getContextByAction model action
getViewByAction action
|> showDialog context
正是出于这个目的,适当的做法?
P.S.我不知道为什么,但我觉得有一个更清洁的解决方案。