wpff#gjallarhorn

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


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.


Solution

  • Currently, there isn't a great solution to this. The application architecture was based (loosely) on Elm, which is geared towards single page applications, which really doesn't include "custom dialog support."

    Right now, the approach you're using is likely similar to what I'd recommend.

    That being said, there are plans to implement a full navigation framework, and windows/dialogs on desktop will be taken into account with that design. In the future, there will likely be guidance around that specifically.