tags:

views:

481

answers:

3

I have a situation like this:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="560"/>
        <ColumnDefinition Width="250"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" /> <!-- status infos & content start -->
        <RowDefinition Height="Auto" /> <!-- status infos -->
        <RowDefinition Height="Auto" /> <!-- status infos -->
        <RowDefinition Height="Auto" /> <!-- status infos -->
        <RowDefinition Height="*"/>     <!-- content ends -->
    </Grid.RowDefinitions>

    <!-- image a list of custom controls directed to the first or second column on all rows here -->

    <SomeCustomControl Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Grid.RowSpan="2" />
</Grid>

As you can see I have 2 Columns, the right one is more or less reserved for status information, the left for content. "SomeCustomControl" contains a control so wide it needs to be set to ColumnSpan="2". Notice there are still the status control in the right column. In SomeCustomControl I have something like this:

<Grid x:Name="LayoutRoot">

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="250"/>
    </Grid.ColumnDefinitions>

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        [...]
        <RowDefinition Height="Auto" /> 
        <RowDefinition Height="*"  />   <!-- problem control here -->
        <RowDefinition Height="Auto" /> 
    </Grid.RowDefinitions>

    <!-- a list of Controls limited to the first column -->

    <ProblemControl Grid.Column="0" Grid.ColumnSpan="2" />
</Grid>

Now, the first Rows of SomeCustomControl contain controls limited to the first column, then there is a row that contains my ProblemControl. The Height of the status controls is not predetermined and depends on the shown status information. The controls in SomeCustomControl that are limited to the first column also have different heights, that are currently determined automatically through the content.

I now have the problem that ProblemControl overlaps with some of my status controls. I tried to calculate the height of my status controls and the limited controls in SomeCustomControl, but as all controls are sized dynamically I can't seem to get correct Heights. The Height of the RowDefinitions all contains Heights of type Auto and value 1, the Heights of the concrete Controls seems to be NaN.

Any ideas as to how I can calc the heights or prevent the overlapings in other ways.

+1  A: 

Have you tried with ActualHeight property on control ?

Andrija
As the controls are just beeing made visible this value seem to contain the "old" values (0 for the elements just beeing made visible and some values depending on the status information that now change).Hmm maybe I can find some event to put the calculation in that is fired after the controls are visible.Thx for the ActualHeight anyway. I guess times of searching excuses why I don't need new glasses are over now :P
gsnerf
A: 

You ought to be able to solve this with proper use of the Grid and some panels (DockPanel and StackPanel can be quite useful). You may also need the HorizontalAlignment or VerticalAlignment properties set to Stretch on some controls.

Your example doesn't have enough in it for us to duplicate your problem or to know that we've addressed it correctly. If you'd like more specific help, please expand the example so we can run it and see your issue.

John Fisher
Please note that I have nested controls here, the second grid is inside the control I referenced in the first grid. I can't take that grid one step up and just solve it with grids and panels. If you wan't to run the example just create 2 controls, with the given grid layouts and place some colored canvas objects. I think I described the rest of the layout.Unfortunately I can't share the exact code due to project restrictions.
gsnerf
Actually, I'm suggesting more nesting, not less. Throw panels into the grid (and grids into those nested panels) if necessary.
John Fisher
+2  A: 

Heya,

I've encountered somewhat of the same problem, but came across the solution recently. The reason why you can't access the width and height properties of a control with width or height set to Auto is that the run time system is querying for the property values before they've been set. The properties "ActualWidth" and "ActualHeight" claim to get the rendered height of controls so in theory, you'd think you could simply wait until the SL application had finished loading and then perform your query, since the controls would be rendered by then and therefore, the ActualHeight/ActualWidth values should be set.

Sadly, this isn't the case either. There doesn't seem to be any guarantee when those values are set, so the workaround I used is to hook into the SizeChanged-event of the control whose values I want. SizeChanged is triggered whenever the width and height properties of a control are changed, so if I handle that event, I am guaranteed that the values are set to something other than NaN.

Do whatever logic you need to perform in a handler for that event, and you'll find the values are set.

Best of luck,

~ Chris