开发者

Data-binding taking too long to update

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 = VerticalO开发者_StackOverflowffset;

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜