试图从 MVVM 应用程序的窗口中检索 DialogResult 时,我偶然发现了这个先前的问题。实施建议的更改后,示例如下所示:
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)
NowDialogResultChanged
在声明之前使用,这在 F# 中当然不会计算。
我似乎找不到可行的解决方案,任何帮助将不胜感激。