Reputation: 449
I want to change the Margin of a stackpannel depending on the height of the previous stackpannel, for example the height of StackPannel1 is 20 and the Margin of stackpannel2 is 0,height of stackpannel1 + 5,0,0. How can I solve my Problem?
Upvotes: 1
Views: 1815
Reputation:
you must refresh.. the solution stackpannel2.Margin = new Thickness(0, StackPannel1.ActualHeight + 5, 0, 0);
seems good to me
Upvotes: 0
Reputation: 12215
This should do the job:
stackpannel2.Margin = new Thickness(0, StackPannel1.ActualHeight + 5, 0, 0);
Make sure to run this code at the appropriate time (i.e. when ActualHeight
actually has been set or changed by the framework), e.g. in response to the FrameworkElement.SizeChanged
event.
Upvotes: 2