I have a main datagrid, then an accordion control below it. In one of the accordion items I have another datagrid that binds to the selected item of the first datagrid. Simple xaml is:
<sdk:DataGrid Name="dgMain" ItemsSource="{Binding SomeSource}" />
<toolkit:Accordion>
<toolkit:AccordionItem Header="Details">
<sdk:DataGrid ItemsSource="{Binding ElementName=dgMain, Path=SelectedItem.Children}"/>
</toolkit:AccordionItem>
</toolkit:Accordion>
I have VerticalAlignment property of the second grid set to “Stretch” so it stretches as different collection sizes are bound to it, but the problem is it only stretches within the AccordionItem size so if I select a new item in the first grid that has more “Children” then I have to scroll the second grid because the AccordionItem didn’t change.
AccordionItem region will only change when i condense and expand it again. Setting VerticalContentAlignment to “Stretch” for the accordion item does not work. I guess because it only triggers this when first expanded.
Does anyone know what else I could try or if I’m missing something. I’d prefer to stick with xaml solution so I can stay MVVM-friendly, but glad to hear everything.
The reason that the
AccordionItemdoesn’t resize properly is because there is a bug in one of its control Parts –ExpandableContentControl. The issue is described here.I think you can either fix its source code or, more easily, replace this control from its default style with a normal
ContentControl. I have included a style here with a normalContentControland tested it in the code that @JohnNicholas provided, and it works.PS. If you want to animate the expanding/collapsing you can just define your own animation in the
AccordionItem‘sCollapsedandExpandedvisual states.It is really a late reply and hope it can be of any help. 🙂