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.我不知道爲什麼,但我覺得有一個更清潔的解決方案。