1

I have a Windows Store XAML app with a "Save" button, which points to an ICommand property in my ViewModel.

<Button Content="Save" 
    Command="{Binding DataContext.SaveNewNote, ElementName=grid, Mode=OneWay}"
    CommandParameter="{Binding DataContext.CurrentItem, ElementName=grid}" />

on the propertychanged event of my Note model, that fires the CanExecutedChanged event - every time (every keystroke). However, this button will only enable/disable once I leave focus of one of the related textboxes.

In other words, there is a "Name" textbox. If String.IsNullOrWhiteSpace(Name.Text), then CanExecute is set to false. This seems to execute with every keystroke.

I would expect to see this bound Save button enable and disable with each keystroke. HOWEVER, instead, I see the button enable/disable only when I tab out of the textbox.

How can I get this bound button to respect the CanExecuteChanged event on every keystroke, instead of when the texbox loses focus?

Robert Seder
  • 1,390
  • 1
  • 9
  • 19
  • 1
    You mean, like changing this http://msdn.microsoft.com/en-us/library/system.windows.data.binding.updatesourcetrigger(v=vs.110).aspx to be PropertyChanged instead of LostFocus? –  Jul 14 '14 at 17:32
  • 1
    I'm not sure if WinRT is restricted in this regard, but there are alternatives; http://stackoverflow.com/questions/4833100/updatesourcetrigger-propertychanged-equivalent-for-a-windows-phone-7-textbox – Patrick Jul 14 '14 at 17:48

1 Answers1

0

The comments by @will and @patrick on the original post both had the correct answer. To do this, you must set the "UpdateSourceTrigger" to "PropertyChanged" and that gives the intended results.

<TextBox Grid.Row="1" PlaceholderText="Enter a short description here" 
    Text="{Binding NoteAbstract, Mode=TwoWay, 
    UpdateSourceTrigger=PropertyChanged}">
</TextBox>
Robert Seder
  • 1,390
  • 1
  • 9
  • 19