I have a simple dialog with two fields for entering a person's name and address, and I only want the OK button to be enabled when they both have values. Here are the relevant parts of my view:
<TextBox Text="{Binding Name}" ... />
<TextBox Text="{Binding Address}" ... />
<Button Content="OK" IsEnabled="{Binding OK, Mode=OneWay}" ... />
And this is my view model:
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
But the OK button is always enabled. What am I doing wrong?