我有一个简单的对话框,其中有两个字段用于输入一个人的姓名和地址,我只希望在它们都有值时启用 OK 按钮。以下是我观点的相关部分:
<TextBox Text="{Binding Name}" ... />
<TextBox Text="{Binding Address}" ... />
<Button Content="OK" IsEnabled="{Binding OK, Mode=OneWay}" ... />
这是我的视图模型:
namespace ViewModels
open FSharp.ViewModule
open FSharp.ViewModule.Validation
open FsXaml
type DialogView = XAML<"Dialog.xaml">
type DialogVM() as self =
inherit ViewModelBase()
let name = self.Factory.Backing( <@ self.Name @>, "", notNullOrWhitespace )
let address = self.Factory.Backing( <@ self.Address @>, "" )
let hasValue str = not( System.String.IsNullOrWhiteSpace( str ))
member x.Name
with get() = name.Value
and set value = name.Value <- value ; self.RaisePropertyChanged( <@ self.OK @> )
member x.Address
with get() = address.Value
and set value = address.Value <- value ; self.RaisePropertyChanged( <@ self.OK @> )
member x.OK with get() = hasValue x.Name && hasValue x.Address
但“确定”按钮始终处于启用状态。我究竟做错了什么?