What is a good approach to show dialog window with Gjallarhorn?

Viewed 123

There is a many question about several good approaches to show dialog window follow to MVVM. But I see Gjallarhorn looks different.

I have to show couple dialogs, for example I have one action per dialog.

type Action = 
    |Show
    |Open
    |Input
    |Change
    |Statistic

and couple of windows

module Views

open FsXaml

...

type StatisticWindow = XAML<"StatWindow.xaml">

type InputWindow = XAML<"InputWindow.xaml">

...

the way I show it

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

It is appropriate approach for this purpose?

P.S. I don't know why but I am feeling there a cleaner solution for the task.

1 Answers
Related