1

In my Control I have a ContentPresenter whose Child is a StackPanel. Inside this StackPanel there are some Elements. The number is undefined because the User of the Control defines it.

Is there a way to bind to the Height of the Elements inside the StackPanel? In Visual Studio's Live Tree there is a Property RenderSize that gives me the Height I need, but binding to this Property does nothing.

I don't know if code helps you but here is my ContentPresenter. InnerContent is a custom Property that takes an UIElement as Setter (the StackPanel).

<ContentPresenter
    x:Name="MyContentPresenter"
    Content="{TemplateBinding InnerContent}" />

I bind to InnerContent.RenderSize.Height but this doesn't do anything.

EDIT: I can't bind to the ActualHeight Property, because the ContentPresenters Height is animated. Its some Kind of Dropdown. The Height is Toggled between 0 and the Height of the StackPanel. And at this Point the ActualHeight of the StackPanel is 0, but the RenderSize is the desired Height.

Am I missing something here? Because this does not look like a big problem.

2
  • 1
    try InnerContent.ActualHeight
    – ASh
    Mar 1, 2017 at 7:47
  • The problem is that you're hosting the StackPanel in a box whose height is set elsewhere. Try reading the content height is much like the dog catching its own tail. An attempt could be hosting the StackPanel in a Canvas or a ScrollViewer, because they don't constrain the size of their children. At the moment of expanding the outer control, you may measure the SP's ActualHeight, then begin the animation. Mar 1, 2017 at 8:41

3 Answers 3

2

Maybe you need to bind to ActualHeight of the StackPanel.

1
  • Look at EDIT please.
    – Febertson
    Mar 1, 2017 at 8:34
2

Try using the FrameworkElement.ActualWidth and ActualHeight properties, instead.

1
  • Look at EDIT please.
    – Febertson
    Mar 1, 2017 at 8:35
0

Okay guys. This was my bad. The ActualHeight Property works fine, even when the ContentPresenters Height Property is 0, the StackPanel's ActualHeight is set right.

Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.