WPF ActualWidth is zero
You could always attach a delgate to the PropertyMetatdata/OnValueChanged
and when ActualHeight/ActualWidth
changes from 0 to something, adjust your scrolling, ActualWidth/ActualHeight
will have a value once its rendered at least once:
LocalNewsControl(){ var descriptor = DependencyPropertyDescriptor.FromProperty(ActualWidthProperty, typeof(TextBlock)); if (descriptor != null) descriptor.AddValueChanged(myTextBlock, ActualWidth_ValueChanged);}private void ActualWidth_ValueChanged(object a_sender, EventArgs a_e){ //Modify you scroll things here ...}
If you want to stick with your dispatcher call - set the priority to loaded then it will be called same time as the loaded event and you should have a value.There is an overload on BeginInvoke that takes a priority also.
Any Control
's ActualHeight
or ActualWidth
will always be zero before they are Loaded
> Measured
> Arranged
> Rendered
.
In your case, I recommend using Loaded
or SizeChanged
event of that TextBlock
to your advantage.