小编Ev_*_*per的帖子

使用Gjallarhorn处理多个命令(来自按钮)的正确方法

窗口上有几个按钮,我试图找到处理命令的好方法.

例如:

我必须执行一些操作:

type Action = 
    |Show
    |Open
    |Input
    |Change
    |Statistic
Run Code Online (Sandbox Code Playgroud)

将其翻译为xaml将是:

<Button Command="{Binding ShowCommand}" />
<Button Command="{Binding OpenCommand}" />
<Button Command="{Binding InputCommand}" />
<Button Command="{Binding ChangeCommand}" />
<Button Command="{Binding StatisticCommand}" />
Run Code Online (Sandbox Code Playgroud)

有点玩图书馆我找到了两种方法来做到这一点,而没有烦人的冗长

1.使用Observable.merge

Binding.createMessage "StatisticCommand" Statistic source
|> Observable.merge (Binding.createMessage "InputCommand" Input source)
//|> Observable.merge ... and so on
|> Observable.subscribe (performAction model.Value)
|> source.AddDisposable
Run Code Online (Sandbox Code Playgroud)

2.创建概括消息

type GeneralMessage = 
    |Perform of Action
    |Update of Message
Run Code Online (Sandbox Code Playgroud)

并将行动信息提升到高水平

let mainComponent source (model : ISignal<Info>) = 

    let info = Binding.componentToView source …
Run Code Online (Sandbox Code Playgroud)

wpf f# gjallarhorn

5
推荐指数
1
解决办法
143
查看次数

标签 统计

f# ×1

gjallarhorn ×1

wpf ×1