Trying to retrieve a DialogResult from a window in a MVVM app, I stumbled on this previous question. After implementing the suggested changes, the sample looks like:
type DialogCloser() =
static let DialogResultProperty =
DependencyProperty.RegisterAttached("DialogResult", typeof<bool>, typeof<DialogCloser>, new PropertyMetadata(DialogResultChanged))
static member GetDialogResult (a:DependencyObject) =
a.GetValue(DialogResultProperty) :?> bool
static member 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)
Now DialogResultChanged
is used before it is declared, which of course doesn't compute in F#.
I can't seem to find a working solution, any help would be appreciated .