1

I use a keybinding to call a Save method. But if I am currently in a textbox and changed the value, this is not commited.

The save happens before the textbox commits the changes and the saved data does not contain the changes.

How can I commit the edit mode of the current GUI element?

InputBindings.Add(new KeyBinding(((MainViewModel)this.DataContext).SavePartCommand, new KeyGesture(Key.S, ModifierKeys.Control)));


class PartViewModel
{
    public override void ExecuteSaveCommand() 
    {
         //commit the edit mode of current GUI element 

         //do the saving
    }
}
juergen d
  • 201,996
  • 37
  • 293
  • 362

1 Answers1

0

One not so elegant way of doing it is setting the Binding to update immediately on changes and not just when losing the focus

<TextBox Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

You would have to do this for every GUI element of your control that can stay in edit mode.

juergen d
  • 201,996
  • 37
  • 293
  • 362
  • 1
    Yep! See http://stackoverflow.com/questions/3765342/in-xaml-is-there-a-way-to-default-the-updatesourcetrigger-to-propertychanged – Charles Mager May 14 '15 at 21:41