I have a TabControl which contains a StackPanel with many Expander. In each Expander I placed an UserControl. So, I have a clear view. The UserControl contains a DataGrid. Now, the problem is, that the height from the DataGrid is not set. If the DataGrid is lager than the window-size no Scrollbar is shown.
<TabControl SelectionChanged="Selector_OnSelectionChanged" Height="Auto">
<TabItem Header="DoSmth">
</TabItem>
<TabItem Header="Misc" Height="Auto">
<StackPanel Height="Auto">
<Expander Header="Misc1" IsExpanded="False" Margin="0,10,0,0">
</Expander>
<Expander Header="Misc2" IsExpanded="False" x:Name="Misc2Expander" Expanded="ExpanderMisc2_OnExpanded" Height="Auto" Margin="0,10,0,0">
<view:Misc2View Background="WhiteSmoke" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Left" VerticalContentAlignment="Top"/>
</Expander>
</StackPanel>
</TabItem>
</TabControl>
If I tried to set the height in the UserControl a Scrollbar is shown, but it is not dynamic.
<view:Misc2View .... height="800" ... />
Update: I already tried to set the height with Binding:
Height="{Binding ElementName=Misc2Expander, Path=Height}"
The
height
of theDataGrid
inside yourUserControl
is not restricted until you set a fixheight
explicitly.This will make
Scrollbar
visible.Edit:
To avoid explicit height, you can use
Grid
withRowDefinitions
instead ofStackPanel
and then bindDataGrid.Height
toExpander.ActualHeight
like this:MainWindow:
UserControl:
Second Edit
If I understand your issue correctly, then you need to set triggers for
RowDefinitions
to set theHeight
of currently expandedExpander
to*
while theHeight
of otherExpanders
remainAuto
like this:You might want to set data binding on
UserControl.Height
instead ofDataGrid.Height
for other elements in yourUserControl
to be visible: