Dependency Property in F #

I have an MVVM application written in F #, and one of the main problems I encountered is closing modal dialogs. I decided to subscribe to the viewmodel RequestedClose, but the DialogResult problem remained. So, I decided to bind DialogResult to the viewmodel property, but soon I realized that DialogResult is not a DependencyProperty. In the end, I tried to implement this accepted answer . But I could not get it to work ... Here is my code:

type DialogCloser() =

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

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

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

member this.DialogResultChanged (a:DependencyObject) (e:DependencyPropertyChangedEventArgs) =
    let window = a :?> Window
    match window with
    | null -> failwith "Not a Window"
    | _ -> window.DialogResult <- System.Nullable(e.NewValue :?> bool)

- this, . : 1) DialogResult DialogCloser 2) , DialogResult get set, DialogResult , DialogCloser.

P.S: , Attached Property, , F #.

+2

Source: https://habr.com/ru/post/1662941/


All Articles