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
heightof theDataGridinside yourUserControlis not restricted until you set a fixheightexplicitly.This will make
Scrollbarvisible.Edit:
To avoid explicit height, you can use
GridwithRowDefinitionsinstead ofStackPaneland then bindDataGrid.HeighttoExpander.ActualHeightlike this:MainWindow:
UserControl:
Second Edit
If I understand your issue correctly, then you need to set triggers for
RowDefinitionsto set theHeightof currently expandedExpanderto*while theHeightof otherExpandersremainAutolike this:You might want to set data binding on
UserControl.Heightinstead ofDataGrid.Heightfor other elements in yourUserControlto be visible: