![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| Guest | How do I retrieve control runtime size values in C#? Hello. I am currently designing a WPF UI programmatically in C#. One of the custom controls I am designing is a horizontal menu containing a set amount of visually displayed buttons. The menu can contain more buttons that is actually displayed and to get to them I have scroll buttons at the side. Now, my Control that contains the buttons is a stackpanel with a horizontal orientation. This stackpanel will be inserted into a grid that is chopped up using GridUnitType.Star values. My problem is that I cannot determine at run time what the size of my stackpanel is. I do not programmatically set its size since it is set to fill up the entire grid horisontally. ( Stretch ). I need the stackpanel's width so that I can determine the correct size of my N buttons that I want to insert into it. For example; my stackpanel's length is 80 and I want it to be able to display 5 buttons so that give a button width of 80/5. I cannot get that 80 at runtime. Any help will be appreciated. Regards, Werner |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: How do I retrieve control runtime size values in C#? Hello, Quote: > For example; my stackpanel's > length is 80 and I want it to be able to display 5 buttons so that > give a button width of 80/5. I cannot get that 80 at runtime. Seems like the stack panel is not the right choice, as it's not for filling the whole space with something. It's a grid-like behavior, rather. Will a grid do instead, star-split for five buttons? If you'd like to have five or six or else number of buttons, varied at runtime based on the space available, then the best way is probably to create another Panel-derived class for that. You'll have two method overrides there, one for the Measure pass (what'd the desired size of your panel be — a sum of all the button widths), and the Layout pass. On the latter, you are given the room available (the length you'd like to get in runtime, that's it), and you can decide how many buttons fit, and what their locations and widths should be. If you cannot employ a Grid for that, a custom panel seems like the best fit. (H) Serge |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: How do I retrieve control runtime size values in C#? Interesting ideas. In the mean time I have figured out that the values I was looking for are located in FrameworkElement.ActualWidth/Height. Because those values are not populated till the final stages of layout. The even SizeChanged fires when the values are populated so I moved all my size calculation code to those handlers. Thanks for your help. W "Serge Baltic" wrote: Quote: > Hello, > Quote: > > For example; my stackpanel's > > length is 80 and I want it to be able to display 5 buttons so that > > give a button width of 80/5. I cannot get that 80 at runtime. > ActualWidth?.. > > Seems like the stack panel is not the right choice, as it's not for filling > the whole space with something. It's a grid-like behavior, rather. Will a > grid do instead, star-split for five buttons? > > If you'd like to have five or six or else number of buttons, varied at runtime > based on the space available, then the best way is probably to create another > Panel-derived class for that. You'll have two method overrides there, one > for the Measure pass (what'd the desired size of your panel be — a sum of > all the button widths), and the Layout pass. On the latter, you are given > the room available (the length you'd like to get in runtime, that's it), > and you can decide how many buttons fit, and what their locations and widths > should be. If you cannot employ a Grid for that, a custom panel seems like > the best fit. > > (H) Serge > > > |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| How do i retrieve only the values from array ? | PowerShell | |||
| How to retrieve service name at runtime | .NET General | |||
| Unable to retrieve value from drop down list (values read from textfile) | VB Script | |||
| How can I control the size of icons in Control Panel? | Vista General | |||