I need to have my DataGrid height auto-expand to meet the height of the tab page it is in. Currently, the DataGrid's height only expands to meet the height of all rows it has data for.
Here is an example of it current appearance: I need the DataGrid to expand to the lower horizonal mark in the example:
Here is my XAML for the UserControl with the DataGrid:
<UserControl x:Class="Nexidia.Esi.ManagementConsole.Views.RamActivesControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:converters="clr-namespace:Nexidia.Esi.ManagementConsole.Views.Converters"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Background="#FFF1F1F1">
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel x:Name="RamControlsPanel" Grid.Row="0" Orientation="Horizontal" Margin="4 4 0 4">
<Button Content="Refresh" Width="60" Margin="0 0 4 0" Click="ButtonRefresh_OnClick" />
<Button Content="New..." Width="60" Margin="0 0 4 0" Click="ButtonNew_OnClick" />
</StackPanel>
<DataGrid x:Name="RamActivesDataGrid"
ItemsSource="{Binding RamActives}"
Grid.Row="1"
AutoGenerateColumns="False"
SelectionMode="Single"
CanUserAddRows="False"
CanUserDeleteRows="False"
CanUserResizeRows="False"
RowHeaderWidth="0"
SelectionUnit="FullRow">
<DataGrid.Resources>
<converters:ListToStringConverter x:Key="ListToString" />
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Header="Created" Width="135" Binding="{Binding CreatedTimeUtc}" />
<DataGridTextColumn Header="Modified" Width="135" Binding="{Binding ModifiedTimeUtc}" />
<DataGridTextColumn Header="Originator" Width="135" Binding="{Binding Originator}" />
<DataGridTextColumn Header="Profiles with access" Width="*" Binding="{Binding Path=RestrictedAccessInstanceProfiles, Converter={StaticResource ListToString}}" />
<DataGridTemplateColumn Header="Actions" Width="90" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Width="15" Cursor="Hand" MouseDown="ImageEdit_OnMouseDown" ToolTip="Edit Instance">
<Image.Source>
<BitmapImage UriSource="../Icons/edit.png" />
</Image.Source>
</Image>
<Image Margin="10 0 0 0" Width="15" Cursor="Hand" MouseDown="ImageStop_OnMouseDown" ToolTip="Stop Instance">
<Image.Source>
<BitmapImage UriSource="../Icons/remove.png" />
</Image.Source>
</Image>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Instance Id" Width="115" Binding="{Binding InstanceId}" />
<DataGridTextColumn Header="Parent Instance Id" Width="115" Binding="{Binding ParentInstanceId}" />
<DataGridTextColumn Header="Original Instance Id" Width="115" Binding="{Binding OriginalInstanceId}" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</UserControl>
EDIT: Added below code snippet to help diagnose the cause.
Here is my XAML for my Tabs Container Control housing the UserControl with the DataGrid:
<UserControl x:Class="Nexidia.Esi.ManagementConsole.Views.RamTabsContainerControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:Views="clr-namespace:Nexidia.Esi.ManagementConsole.Views"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Background="#FFF1F1F1">
<StackPanel Orientation="Vertical">
<StackPanel x:Name="RamControlsPanel" Grid.Row="0" Orientation="Horizontal" VerticalAlignment="Center" Margin="0 10 0 10" >
<RadioButton x:Name="DateUtc" GroupName="datesStyle" Content="Display dates in UTC" IsChecked="True" Margin="6 0 0 0"/>
<RadioButton x:Name="DateLocal" GroupName="datesStyle" Content="Display dates in local times" Margin="20 0 0 0"/>
</StackPanel>
<TabControl HorizontalAlignment="Stretch" x:Name="OptionsTabControl" Grid.Row="0" Padding="6">
<TabItem Header="Active Instances" x:Name="RamActivesTabOption">
<StackPanel Orientation="Vertical">
<Views:RamActivesControl x:Name="RamActives" />
</StackPanel>
</TabItem>
<TabItem Header="History" x:Name="RamHistoriesTabOption">
<Views:RamHistoriesControl x:Name="RamHistories" />
</TabItem>
</TabControl>
</StackPanel>
</Grid>
Your code snippets are not enough to diagnose the cause.
I am almost 100% sure that the problem is not in the DataGrid, but in the overall layout. If you check the height value of your UserControl RamActivesControl
at runtime, you will notice that the value of its ActualHeight property is limited and is not equal to the entire available space. And then this restriction applies to the child DataGrid. It is highly likely that a StackPanel is used somewhere higher in the layout.