segunda-feira, 16 de abril de 2012 13:25
Whenever I change my textbox/label from the code behind, the width doesn't update until my function stops running.
and the width returned was 50,
then I change the content to "test test"
I would still get 50 as width unless I restart this function.
Why doesn't the width change when I change the content?
How can I change the width immediately according to the content?
Todas as Respostas
segunda-feira, 16 de abril de 2012 13:37
Can you show the code that you are using to see if the width expands ?
And maybe you should use the label.SizeChanged event to update the value instead.
Developing is part of being a developer.
segunda-feira, 16 de abril de 2012 13:41
I just had a button to show me this:
MessageBox.Show(labeltext.ActualWidth.ToString()); labeltext.Content = "test test"; MessageBox.Show(labeltext.ActualWidth.ToString());
The width that was returned was the same(original text was different).
Also I use ActualWidth since regular Width gives me NaN..How can I get the new width?
segunda-feira, 16 de abril de 2012 14:31The width will not change untill another layout pass happens (when the function ends the UI will update). You will have to force this update if you want it immediately. You can look into the Measure method (possibly UpdateMeasure or UpdateLayout), or you could run the code on a background thread, and Invoke the Label Content change with a Render Priority.
- Marcado como Resposta Igor_abc segunda-feira, 16 de abril de 2012 14:38
segunda-feira, 16 de abril de 2012 14:38
UpdateLayout did the trick, thanks.