View Single Post
Old 10-28-2008   #3 (permalink)
WernerG


 
 

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 SpecsSystem Spec