6
Vote

AccordionItem Grows Once when Children Added

description

When children are added to an AccordionItem the ExpandablecontentControl expands the first time, but not on subsequent children being added.
 
To reproduce expand the top item then press the button to add a TextBlock. The accordion size increases. When the button is clicked again the size does not change, but if you expand and collapse the accordion item the correct size is set.
 
 
<UserControl xmlns:layoutToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit" xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit" x:Class="SilverlightApplication16.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<Grid x:Name="LayoutRoot">
    <StackPanel Orientation="Vertical">
        <Button Click="Button_Click" Content="Click Me To Add Text Box"></Button>
        <layoutToolkit:Accordion SelectionMode="ZeroOrMore">
            <layoutToolkit:AccordionItem x:Name="ac1" >
                <StackPanel Orientation="Vertical" x:Name="sp2">
                    <TextBlock Text="1"></TextBlock>
                </StackPanel>
            </layoutToolkit:AccordionItem>
            <layoutToolkit:AccordionItem>
                <StackPanel Orientation="Vertical" x:Name="sp3">
                    <TextBlock Text="2"></TextBlock>
                </StackPanel>
            </layoutToolkit:AccordionItem>
            <layoutToolkit:AccordionItem>
                <StackPanel Orientation="Vertical" x:Name="sp4">
                    <TextBlock Text="3"></TextBlock>
                </StackPanel>
            </layoutToolkit:AccordionItem>
            <layoutToolkit:AccordionItem>
                <StackPanel Orientation="Vertical" x:Name="sp5">
                    <TextBlock Text="4"></TextBlock>
                </StackPanel>
            </layoutToolkit:AccordionItem>
        </layoutToolkit:Accordion>
        <controlsToolkit:Expander ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" MaxHeight="200">
            <StackPanel Orientation="Vertical" x:Name="sp"></StackPanel>
        </controlsToolkit:Expander>
        <TextBlock Text="End"></TextBlock>
    </StackPanel>
</Grid>
</UserControl>
 
namespace SilverlightApplication16
{
public partial class MainPage : UserControl
{
    int _i = 0;
    public MainPage()
    {
        InitializeComponent();
    }
 
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        TextBlock tb = new TextBlock();
        tb.Text = "New Row" + _i;
        _i++;
        sp2.Children.Add(tb);

    }
 
 }
}

comments

epodolyak wrote Aug 25, 2009 at 5:29 PM

Is there any workaround until it not fixed?

jd_hixon wrote Aug 26, 2009 at 8:46 AM

It appears as though the ExpandableContentControl is given a fixed height. If you propogate the visual tree and find the expandable content control and set the height to Double.NaN it will expand. However, some actions (I don't have a full list) appear to reset the height.

epodolyak wrote Aug 26, 2009 at 2:25 PM

Great, it helped, thanks!

jd_hixon wrote Aug 27, 2009 at 8:18 AM

You may also want to checkout this thread http://silverlight.net/forums/t/97918.aspx