WPF DataGrid in release Accordion Height

I use the latest WPF Toolkit , but I ran into a height problem when I have a large record set associated with a DataGrid inside an AccordionItem element. The height of Accordion itself scales very well, but the DataGrid inside the accordion control does not get a ScrollBar or gets a constraint in any way, so the records are hidden.

I know that I most likely missed something very simple (like binding from the DataGrid height property to the Accordion, but that seems messy)

here is a cut-out version of the code (and yes, it has the same problem if you bind in a large set of records)

 <UserControl> <layouttoolkit:Accordion x:Name="ReportSelector" HorizontalAlignment="Stretch"> <layouttoolkit:AccordionItem Header="grid 1"> <dg:DataGrid AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" SelectionMode="Single"> ... </dg:DataGrid.Columns> </dg:DataGrid> </layouttoolkit:AccordionItem> <layouttoolkit:AccordionItem Header="grid 2"> <dg:DataGrid AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" SelectionMode="Single"> ... </dg:DataGrid.Columns> </dg:DataGrid> </layouttoolkit:AccordionItem> <layouttoolkit:AccordionItem Header="grid 3"> <dg:DataGrid AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" SelectionMode="Single"> ... </dg:DataGrid.Columns> </dg:DataGrid> </layouttoolkit:AccordionItem> </layouttoolkit:Accordion> </UserControl> 
+6
height wpf xaml datagrid wpftoolkit
source share
2 answers

It seems that my initial idea was correct - the only way to solve this problem is to link the MaxHeight DataGrid with ActualHeight in AccordionItem

Adding the following property to each DataGrid did the trick

 MaxHeight="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type layouttoolkit:AccordionItem}},Path=ActualHeight}" 
+8
source share

I'm so glad I came across this! This QA must be supported. I had a similar problem, except for the width of the columns.

My DataGrid had Width = "Auto", as well as some column widths *. Outside the Accordion, the DataGrid was rendered perfectly, but inside the Accordion, the width of all columns will be compressed to 10 pixels each. I can’t understand why. Could it be a mistake?

I noticed that if I set a static width, like 400 instead of Auto, the columns would display correctly. Then I tried to bind the DataGrid Width to the AccordionItem ActualWidth, just like you did, and now it works fine. Thanks sir!

+2
source share

All Articles