我已经使用事件驱动的MVVM几个星期了(第一次在F#中使用设计模式),我喜欢将视图和模型以及“功能”控制器分离的想法。但是,当我阅读一本关于WPF的书时,我会觉得如果我能直接讲述一些事件的话,会更容易。另外,在某些情况下,我需要从后面的代码中获得一个控件。
更具体而言:
有没有人分享过这种经历,还是我还错过了什么?返回到FsXaml或polyglot MVVM是明智的吗?
发布于 2015-07-16 09:36:50
实际上,代码很容易扩展。基于演示,我能够将文本框转换为数字文本框。这样做的代码是非常基本的,但我的意图是定义一个自定义事件访问器。这可以通过以下方式实现:
使用以下内容扩展UserControl.xaml报头:
xmlns:fsxaml="http://github.com/fsprojects/FsXaml"
fsxaml:ViewController.Custom="{x:Type views:CompositionUserControl}"并替换UserControl.xaml.fs中的原始代码:
namespace Space.Views
open FsXaml
type UserView = XAML<"View/UserControl.xaml", true>
type CompositionUserControl () =
member __.ViewModel = Space.ViewModels.UserControlViewModel(Space.Models.Handling.proces)使用
namespace Space.Views
open FsXaml
open System
type UserView = XAML<"View/UserControl.xaml", true>
type CompositionUserControl () =
inherit UserControlViewController<UserView>()
let numeric (txt : string) =
try txt |> int with
| :? System.FormatException -> 0
| _ -> 1
override this.OnLoaded view =
view.Box.PreviewTextInput.Add(fun e -> if numeric e.Text = 0 then e.Handled <- true)
member __.ViewModel = Space.ViewModels.UserControlViewModel(Space.Models.Handling.proces)编辑
回顾这篇文章,以下是我最初问题的进展:
如何关闭XAML文件中定义为用户控件的窗口
使用附加属性DialogCloser。
如果我能直接加入事件,似乎对按钮的需求就会减少(触发持有状态的布尔人),从而产生更自动的感觉。
这里的关键是学习:
https://stackoverflow.com/questions/31407930
复制相似问题