I tried placing a XAML Grid inside of a ScrollViewer, but the grid automatically resizes with the content. When I add 50 items to ListA, the vertical scroller shows up. If I set the VerticalScrollBarVisibility="Disabled" then the Grid displays as it should. What I'd really like is for the ScrollViewer to be disabled unless the width falls below the minHeight of the Grid (480 in the example) but I can't seem to figure out how to make that happen. What's the best way to achieve this?
XAML
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
<!-- Control Layout Root -->
<Grid MinHeight="480" MinWidth="640">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.20*" />
<ColumnDefinition Width="0.20*" />
<ColumnDefinition Width="0.30*" />
<ColumnDefinition Width="0.15*" />
<ColumnDefinition Width="0.15*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="34" />
<RowDefinition Height="34" />
<RowDefinition Height="34" />
<RowDefinition Height="34" />
<RowDefinition Height="34" />
<RowDefinition Height="428*" />
<RowDefinition Height="34" />
</Grid.RowDefinitions>
<!-- Constituents ListBox -->
<Label Content="List A"
Grid.Row="0"
Height="28"
HorizontalAlignment="Left"
Margin="6,6,0,0"
VerticalAlignment="Top" />
<ListBox x:Name="ListA"
Grid.Row="1" Grid.RowSpan="5"
Margin="6,9,9,9"
VerticalAlignment="Stretch"/>
<!-- Equivalency ListBox -->
<Label Content="List B"
Grid.Column="1" Grid.Row="0"
Margin="8,6,0,0"
Height="28"
HorizontalAlignment="Left"
VerticalAlignment="Top" />
<ListBox Grid.Column="1" Grid.Row="1" Grid.RowSpan="5"
Margin="8,9,9,9" VerticalAlignment="Stretch"/>
<Label Content="Details" Height="28" HorizontalAlignment="Left" Margin="9,6,0,0" VerticalAlignment="Top"
Grid.Column="2" Grid.Row="0" Grid.ColumnSpan="3" Width="495" />
<!-- Primary Method -->
<Label Content="Info" Height="28" HorizontalAlignment="Left" Margin="9,9,0,0" VerticalAlignment="Top"
Grid.Column="2" Grid.Row="1" />
<TextBox
Grid.Column="2" Grid.Row="2"
Height="23" HorizontalAlignment="Stretch"
Margin="9,0,9,0" VerticalAlignment="Stretch" />
<!-- Matrix -->
<Label Content="More Info" Height="28" HorizontalAlignment="Left" Margin="8,9,0,0" VerticalAlignment="Top"
Grid.Column="3" Grid.Row="1" />
<TextBox Grid.Column="3"
Grid.Row="2"
Height="23"
HorizontalAlignment="Stretch"
Margin="9,0,9,0" />
<!-- Class -->
<Label Content="???" HorizontalAlignment="Left" Margin="8,9,0,0"
Grid.Column="4" Grid.Row="1" Height="28" VerticalAlignment="Top" Width="46.45" />
<TextBox Height="23" HorizontalAlignment="Stretch" Margin="9,0,9,0" VerticalAlignment="Stretch"
Grid.Column="4" Grid.Row="2"/>
<!-- Start Date -->
<Label Content="x" Height="28" HorizontalAlignment="Left" Margin="9,9,0,0" VerticalAlignment="Top"
Grid.Column="2" Grid.Row="3" />
<TextBox Grid.Column="2" Grid.Row="4" Margin="9,1,9,0"
Height="23"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
<!-- End Date -->
<Label Content="y" Height="28" HorizontalAlignment="Left" Margin="9,9,0,0" VerticalAlignment="Top"
Grid.Column="3" Grid.Row="3" />
<TextBox Grid.Column="3" Grid.ColumnSpan="2" Grid.Row="4" Margin="9,1,9,0"
Height="23"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
<!-- Equivalency Data Grid -->
<DataGrid AutoGenerateColumns="False"
Grid.Column="2" Grid.ColumnSpan="3" Grid.Row="5"
Margin="9,18,6,9" VerticalAlignment="Stretch">
<DataGrid.Columns>
<DataGridTextColumn Header="Column A" Width="140" />
<DataGridTextColumn Header="Column B" Width="70" />
<DataGridTextColumn Header="Column C" Width="100"/>
<DataGridTextColumn Header="Details" Width="*"/>
</DataGrid.Columns>
</DataGrid>
<Button Content="Exit" Grid.Row="6" />
<Button Content="Reset" Grid.Row="6" Grid.Column="4" />
</Grid>
</ScrollViewer>
Code Behind (populate list)
public MainWindow()
{
this.InitializeComponent();
// Insert code required on object creation below this point.
for( int i = 0; i < 50; i++ ){
ListA.Items.Add( "Item " + i );
}
}