I have an application where bindings work almost as they should, there is just one problem:
Some GUI elements update the underlying data type "on exit" i.e. when focusing on something else. However, this doesn't happend when I click "execute" or "save" (saving settings). So if the last setting that was set was a textbox and the user didn't click somewhere else, the updated setting value is not included into the execution / setting save.
- Is there a way to do this manually at execute/save?
- Why doesn't my clicking on execute/save work as a focus change? Maybe it does but it doesn't happend until after the event for the button i开发者_运维知识库s run?
You can use this to explicitly update the binding for a specific textbox element or the focused textbox element in your execute/save method and still use LostFocus for the UpdateSourceTrigger property:
public static void UpdateBinding()
{
UpdateBinding(Keyboard.FocusedElement as TextBox);
}
public static void UpdateBinding(TextBox element)
{
if (element != null)
{
var binding = element.GetBindingExpression(TextBox.TextProperty);
if (binding != null)
{
binding.UpdateSource();
}
}
}
Try using UpdateSourceTrigger="PropertyChanged"
on your textbox binding
EDIT
or use UpdateSourceTrigger="Explicit"
and call the update method in your bindings when handling your button click
精彩评论