I came up against a problem, it seems like a pretty specific problem, but none the less the solution took me a while to figure out, so worth sharing!
My problem: I have a user control that contains some text among other things, but the text is of various length, the containing textblock therefore, like the user control has a dynamic height (set the Height property to System.Double.NaN).
There are n instances of the user control within a StackPanel, as a control is added to the StackPanel I want a StoryBoard which animates the Height and the Opacity. The Height of course I do not know.
So I need to the set the Value of the Double Animation at runtime.
The XAML for the StoryBoard.
Firstly I need to new up the user control, set all the properties, add the control to the StackPanel, set the height of the DoubleAnimation and fire the StoryBoard.
Just simply going UserControl.ActualHeight will return 0 because the layout engine has not calculated the ActualHeight property. Which is the problem!!!
So we need to use the Dispatcher class (you can find out more on MSDN).
In the User Control (UserComment)
Hope this helps!
comments powered by Disqus