views:

218

answers:

1

I have an Accordion and the height of its content can be dynamically resized. I would like to see the Accordion dynamically respond to the child item's height, but I'm having trouble doing this.

    <lt:Accordion Name="MyAccordion"
                  SelectionMode="ZeroOrOne"
                  HorizontalAlignment="Stretch">
        <lt:AccordionItem Name="MyAccordionItem"
                          Header="MyAccordion"
                          IsSelected="True"
                          HorizontalContentAlignment="Stretch"
                          VerticalAlignment="Stretch">
            <StackPanel>
                <Button Content="Grow" Click="Grow"/>
                <Button Content="Shrink" Click="Shrink"/>
                <TextBox Name="GrowTextBox"
                         Text="GrowTextBox"
                         Height="400"
                         Background="Green"
                         SizeChanged="GrowTextBox_SizeChanged"/>
            </StackPanel>
        </lt:AccordionItem>
    </lt:Accordion>


    private void Grow(object sender, System.Windows.RoutedEventArgs e)
    {
        GrowTextBox.Height += 100;
    }

    private void Shrink(object sender, System.Windows.RoutedEventArgs e)
    {
        GrowTextBox.Height -= 100;
    }

    private void GrowTextBox_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
    {
        MyAccordion.UpdateLayout();
        MyAccordionItem.UpdateLayout();
    }

Mind you, if I collapse and then re-open the accordion, it takes shape just the way I want, but I'd like this resizing to occur immediately when the child resizes.

I feebly attempted to fix this by adding a SizeChanged event handler that calls UpdateLayout() on the Accordion and AccordionItem, but this doesn't have any visual effect. I can't figure out where proper resizing takes place inside the Accordion control. Does anyone have an idea?

A: 

I have a similar problem, my simple hack is as follows:

private void GrowTextBox_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
{
        MyAccordionItem.Measure(new Size());
        MyAccordionItem.UpdateLayout();
}

Hope it works for you too..

Cheers

Titan
Hmm, this sounds promising but it doesn't seem to fix the problem. Can I see what your XAML looks like?
I have a datagrid within a datagrid, and on sizechanged of the inner grid, I included the code behind as above. Let me try on the buttons and get back to you.
Titan