2017-08-07 135 views
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.我不知道为什么,但我觉得有一个更清洁的解决方案。

回答

4

目前,没有一个很好的解决方案。该应用程序体系结构基于(松散地)在Elm上,该应用程序体系结构适用于单页应用程序,它实际上不包括“自定义对话框支持”。

现在,您使用的方法可能与我推荐的类似。这就是说,有计划实施一个完整的导航框架,桌面上的窗口/对话框将考虑到该设计。未来,可能会有专门的指导。

相关问题