views:

39

answers:

1

In my application I have this code in my view model:

hiddenTextContainer.PreHideVerticalOffset = VerticalOffset;

            hiddenTextContainer.HiddenText = Text.Remove(SelectionStart, SelectionLength);
            hiddenTextContainer.HasHiddenText = true;
            hiddenTextContainer.NonHiddenTextStart = SelectionStart;
            Text = Text.Substring(SelectionStart, SelectionLength);           
            SelectionStart = Text.Length;

            hiddenTextContainer.ImmediatePostHideVerticalOffset = VerticalOffset;

This code is used to hide selected text in a textbox. Text is a string property data bound to the text property of a textbox and VerticalOffset is a double property data bound to the VerticalOffset property of that same textbox.

I need to save the VerticalOffset before and after the hiding of selected text takes place, but with my code below both hiddenTextContainer.PreHideVerticalOffset and hiddenTextContainer.ImmediatePostHideVerticalOffset are always set to the same value no matter what.

I have figured out that this is because the text of the textbox has not been updated by the time the code reaches: hiddenTextContainer.ImmediatePostHideVerticalOffset = VerticalOffset;

Is there any way I can fix this?

+1  A: 

It is probably not that the property of text is being updated too slowly, it's that the Measure and Arrange is being performed asynchronously. I'd suggest explicitly calling Window.UpdateLayout (or similar, depending on the container you need to recalculate).

Possibly, you'll need to do, InvalidateArrange or InvalidateMeasure first.

nedruod
Thanks! It worked beautifully.
Justin