views:

20

answers:

0

I have a ContentControl bound to a PhoneNumber object, and the control's Style.Triggers applies different ContentTemplates when the control has or doesn't have keyboard focus.

    <Setter Property="ContentTemplate" Value="{StaticResource DisplayPhoneNumberDataTemplate}" />
    <Style.Triggers>
        <Trigger Property="IsKeyboardFocusWithin" Value="True">
            <Setter Property ="ContentTemplate" Value="{StaticResource EditPhoneNumberDataTemplate}" />
        </Trigger>
    </Style.Triggers>

When it does not have focus, we see plain text that displays the formatted string representation of the phone number.

When focused, we see 3 editable TextBox elements, each two-way bound to a property of the PhoneNumber object, AreaCode, Exchange, and SubscriberLine, and each set to update the source when the control loses focus.

The problem I'm facing is that when I tab out of the last TextBox (or click outside the control from any of them), changes do not get pushed back to the source. It seems like the ContentControl's loss of keyboard focus trumps this process and of course when the ControlTemplate changes the TextBox in question ceases to exist.

The reason I can't trigger updates to the source when the property changes instead of when the control loses focus is that my setter for each property is pushing the update to an undo command stack, and I don't want an undo command for every single character typed or deleted -- just for the whole change that occurred while editing the field.

Any ideas how I might set the property when the TextBox loses focus before the ContentTemplate changes?