Link to home
Start Free TrialLog in
Avatar of Bronco78th
Bronco78thFlag for United Kingdom of Great Britain and Northern Ireland

asked on

C# WPF How to Scale a Groupbox to Fit Content.

Hey all,

ill upload a piccy if nessary but hopefully you will be able to follow.

 I have a WPF interface where the user can add textboxes/textblocks as they find nessary, all textboxes/textblocks are already created but start in a  Collapsed state until the User adds them and they become 'Visible'.

All these Collapsed elements are in Collapsed Group Boxes which are themselves in a single stackpanal.

One of these group boxes, in particular, has 8 Textboxes in it.  Its highly unlikely the end user will use all 8 at the same time, Most people however will use 2-4 of the textboxes.

when a user adds 2 or 4 textboxes the groupBox containing them also becomes visable, the problem is the Groupbox is massive, as its size caters for 8 textboxes rather than 2 or 4.

Is it possible to compact the groupbox so its size is relative to how many textboxes are added by the user So the groupbox would be smaller if 2 or 4 textboxes are added and full size if the user adds all 8 for example?

Many Thanks,

John




Avatar of dimaj
dimaj
Flag of United States of America image

You could add some logic that would change the width of your group box based on how many fields you have visible. Just add an even handler for VisibileChanged (or something of that sort). Then, in your handler loop through all your fields and for every visible field, increment your counter. Once done with your loop change the width of the groupbox based on visibility counter.
Avatar of Bronco78th

ASKER

Bah,

Just made a complete noob of myself as I suddenly thought after posting

whats wrong with setting the Height property of the groupbox for when  each 2,4,6,8 textboxes are added? Simples!!

Ill leave the thread open as others may have other ways of doing it which might be good for future reference, will award point in the morning as clearly I need sleep.

Many thanks for the quick reply Dimaj, will award points etc in the morning :)

Regards,

John
SOLUTION
Avatar of dimaj
dimaj
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Snarf0001
Snarf0001
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial