I have the following window setup:
<Window x:Class="SearchWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:POR"
mc:Ignorable="d"
Title="SearchWindow"
Height="450"
Width="1000"
Loaded="Window_Loaded"
ResizeMode="NoResize"
Icon="/Images/receipt.ico"
WindowStartupLocation="CenterScreen">
<Grid>
<StackPanel Orientation="Vertical">
<!-- Search Box -->
<StackPanel x:Name="SP_SearchBox" Margin="0,5,0,0"
DockPanel.Dock="Top" Orientation="Horizontal" HorizontalAlignment="Center">
<Border CornerRadius="6"
BorderBrush="Gray"
BorderThickness="2"
Padding="1">
<StackPanel Orientation="Horizontal">
<Image Source="\Images\magnify.png" Height="21" VerticalAlignment="Center"/>
<TextBox x:Name="TB_search"
Width="220"
FontSize="12"
BorderThickness="0"
VerticalAlignment="Center"
HorizontalContentAlignment="left"
Padding="0,0,0,0"
Text="Search..."
Background="Transparent"
Foreground="Gray"
TextChanged="TB_Search_TextChanged"
PreviewKeyUp="TB_search_PreviewKeyUp"/>
<Image x:Name="BTN_Clear" Source="\Images\close.png" Height="20"
VerticalAlignment="Center" Visibility="Visible" Cursor="Hand"
MouseLeftButtonUp="BTN_Clear_MouseLeftButtonUp"/>
</StackPanel>
</Border>
</StackPanel>
<!-- Auto Suggestion box -->
<Popup x:Name="Popup" IsOpen="False" PlacementTarget="{Binding ElementName=SP_SearchBox}"
AllowsTransparency="True" PopupAnimation="Slide" Width="263" HorizontalOffset="-2" VerticalOffset="-2">
<Border CornerRadius="6"
BorderBrush="Gray"
BorderThickness="1"
Padding="1">
<ListView x:Name="LV_hints" Visibility="Visible" BorderThickness="0"
SelectionChanged="LV_hints_SelectionChanged"/>
</Border>
</Popup>
<!-- Grid 1 -->
<StackPanel Orientation="Vertical">
<DataGrid x:Name="DG_Orders" ItemsSource="{Binding}"
Margin="6" VerticalContentAlignment="Center" Visibility="Hidden">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Click="BTN_ShowItems_Click"
Margin="3">Show Items</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<!-- Grid 2 -->
<DataGrid x:Name="DG_OrderItems" ItemsSource="{Binding}"
Margin="6" VerticalContentAlignment="Center" Visibility="Hidden">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button x:Name="BTN_Receipt" Click="BTN_Receipt_Click"
Margin="3">Receipt</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</StackPanel>
</StackPanel>
</Grid>
I cannot figure out why am I not getting a scroll bar when the bottom DataGrid
has more data and appears off the window at the bottom of it.
I've tried using <DockPanel>
in various places, like the top-most <StackPanel>
but that still did not show me any scroll bars. I have read that using controls such as <DockPanel>
or <StackPanel>
should automatically give me a scrollbar when the content does not fit on the window, but in my case it just goes off screen.
I have also tried using <Grid.ColumnDefinitions>
and <Grid.RowDefinitions>
and having a row and a column on the sides as well as top and bottom for 5px margin for the content, but again, the bottom DataGrid
just expands down and cuts off on the window.
Thanks in advance!