0

Im writing a WPF application where usercontrols are added to a TabControl at runtime - creating a tab for each user control. The problem then is...these controls can have different width and height which means the tabcontrol must adjust its own width and height accordingly. I tought this would be a simple exercise of just accessing the usercontrols Height/ActualHeight properties, but these are NaN/0.0 Is it not possible to get this information?

cht
  • 1
  • 1
  • But what for TabControl has to adjust its own size? Could you explain? – Artiom Aug 15 '12 at 11:35
  • if the tab control is 300x300 and i add a new tabitem to it that is 400x400, some of it is not shown, therefor i have to check if the tabcontrol needs resizing after each control is added – cht Aug 15 '12 at 12:09
  • I would avoid to change the TabControl's size. It would scare me being an user. Instead I would recommend to place controls in the **ScrollViewer**. Is it suitable for you? – Artiom Aug 15 '12 at 12:15
  • No a ScrollViewer is not an option - the control must scale to largest added control so it is fully viewable – cht Aug 15 '12 at 12:19

1 Answers1

0

I can propose next solution:

When you add a new control to the TabControl (is it a TabControl or a TabItem?) set bindings for the Width and Height properties. Create a converter to convert sizes of added controls to the size of Owner (in case if you need to have minimum size).

ActualWidth and ActualHeight properties perhaps are 0 because control wasn't measured yet. Look this thread

Community
  • 1
  • 1
Artiom
  • 7,694
  • 3
  • 38
  • 45