DialogResult in F#

僤鯓⒐⒋嵵緔 提交于 2019-12-02 03:18:07
Tomas Petricek

I'm not a WPF expert, but in this related C# solution, the DialogResultsChanged method is static. If you define the method as static in F# too, you should be able to reference it before it is declared (using the full name DialogCloser.DialogResultsChanged), so something like the following should do the trick:

type DialogCloser() =

    static let DialogResultProperty =
        DependencyProperty.RegisterAttached
            ( "DialogResult", typeof<bool>, typeof<DialogCloser>, 
              new PropertyMetadata(DialogCloser.DialogResultChanged))

    static member GetDialogResult (a:DependencyObject) =
        a.GetValue(DialogResultProperty) :?> bool

    static member SetDialogResult (a:DependencyObject) (value:string) = 
        a.SetValue(DialogResultProperty, value)

    static member DialogResultChanged 
            (a:DependencyObject) (e:DependencyPropertyChangedEventArgs) =
        let window = a :?> Window
        match window with
        | null -> failwith "Not a Window"
        | _ -> window.DialogResult <- System.Nullable (e.NewValue :?> bool)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!