views:

38

answers:

2

Hi,

I have a listbox inside another list box, in inner list box listboxitems height may grow or shrink. My problem is that when the inner items shrink the outer list box doesn't re-render its height. Thus - stays with the previous height before the inner list shrinked.

I have tried so many things here, among Invalidate of all types, selection and de-selection of the list box item that should be updated and more - nothing helps....

Can anyone pls help me with this?

Thanx, Gili

A: 

Just for the heck of it I did the following:

    <Grid x:Name="LayoutRoot">
    <ListBox HorizontalAlignment="Left" Width="283" VerticalAlignment="Top">
        <ListBox Margin="0,0,-274,0">
            <ListBoxItem Content="Text"/>
            <ListBoxItem Content="Text"/>
            <ListBoxItem Content="Text"/>
            <ListBoxItem Content="Text"/>
            <ListBoxItem Content="Text"/>
            <ListBoxItem Content="Text"/>
        </ListBox>
        <ListBox Margin="0,0,-274,0">
            <ListBoxItem Content="Text"/>
            <ListBoxItem Content="Text"/>
            <ListBoxItem Content="Text"/>
            <ListBoxItem Content="Text"/>
            <ListBoxItem Content="Text"/>
            <ListBoxItem Content="Text"/>
        </ListBox>
        <ListBox Margin="0,0,-274,0">
            <ListBoxItem Content="Text"/>
            <ListBoxItem Content="Text"/>
            <ListBoxItem Content="Text"/>
        </ListBox>
        <ListBox Margin="0,0,-274,0">
            <ListBoxItem Content="Text"/>
            <ListBoxItem Content="Text"/>
            <ListBoxItem Content="Text"/>
            <ListBoxItem Content="Text"/>
            <ListBoxItem Content="Text"/>
            <ListBoxItem Content="Text"/>
        </ListBox>
    </ListBox>
</Grid>

Now I realize the items in the list boxes are not created at run-time, however I created a little button with click handler which adds items to one of the middle listboxes, and everything resizes appropriately.

If you post your code, we can take a look and see what is out of whack.

OffApps Cory
A: 

Take this for example:

    <ListBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="500">
        <ListBox x:Name="Item1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="300" BorderBrush="Red" BorderThickness="5">
            <ListBox.Items>
                <RichTextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="300" SizeChanged="OnInnserItemSizeChanged"/>
                <RichTextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="300"/>
                <RichTextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="300"/>
            </ListBox.Items>
        </ListBox>
        <ListBox x:Name="Item2" BorderBrush="Green" BorderThickness="5" Width="300" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
            <ListBox.Items>
                <RichTextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="300"/>
                <RichTextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="300"/>
                <RichTextBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="300"/>
            </ListBox.Items>
        </ListBox>            
    </ListBox>

Now, when i run it and click 'Enter'/'Return' in the one of the RichTextBoxes, the outer listbox item stretches to match the new size - but when i delete the newly added row it doesn't resize back to its original size...

Thanx, Gili

Gili