I want to set the UpdateSourceTrigger to an event of a control:
<TextBox Text="{Binding Field, UpdateSourceMode=btnOK.Click}">
<Button Name="btnOK">
<Button.Triggers>
<Trigger>
<!-- Update source -->
</Trigger>
</Button.Triggers>
</Button>
I thought about two ways:
- Set UpdateSourceMode or some other stuff in the binding.
- Set an EventTrigger that updates source on button click.
Possible, or I have to do it with code?
I know it's been a while, but I came across the same issue and want to share my solution. Hope it will be helpful for somebody.
Here is my solution:
XAML:
Behaviour definition (inherited from TargetedTriggerAction):
Please note that it's important to attach TextBoxUpdateSourceAction to parent container (StackPanel in example code).
You'll have to use code. Specifically:
UpdateSourceTrigger=Explicit
on theTextBox
.UpdateSource
when the user clicks theButton
.However, you can put the code in the code behind or in an attached behavior.