I have a DataGrid that is populated from my MySQL Database in the code behind like this.
public void FillGrid()
{
string sql = "SELECT * FROM employees ORDER BY firstname";
using (MySqlConnection cnn = DatabaseInterface.OpenCnn())
{
using (MySqlCommand cmdSel = new MySqlCommand(sql, cnn))
{
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(cmdSel);
da.Fill(dt);
DataTable.DataContext = dt;
}
cnn.Close();
}
}
The DataGrid for some reason can not be scrolled, even if the Data is well out of the viewable window. However the Scrollbar, Visibility set to "Auto", is displayed as soon as the Data is outside of its container. It also has the kind of "Bar" inside the Scrollbar, indicating that it should be scrollable. But not the mousewheel nor the bar itself can be used to scroll through. I tried
This is the XAML:
<Grid Margin="72,89,72,69">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<DataGrid x:Name="DataTable" Grid.Row="1" HeadersVisibility="None" Background="Transparent" VerticalScrollBarVisibility="Auto" MaxHeight="231" GridLinesVisibility="Horizontal" HorizontalGridLinesBrush="White" HorizontalScrollBarVisibility="Disabled" RowBackground="Transparent" AlternatingRowBackground="Transparent" CanUserResizeColumns="False" CanUserAddRows="False" CanUserResizeRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserSortColumns="False" AutoGenerateColumns="False" IsReadOnly="True" IsHitTestVisible="False" ItemsSource="{Binding }" Foreground="White" BorderBrush="{x:Null}" FontWeight="Bold" FontSize="16">
<DataGrid.Columns>
<DataGridTextColumn Header="Kürzel" Binding="{Binding kuerzel}" Visibility="Collapsed" CanUserResize="False"></DataGridTextColumn>
<DataGridTextColumn Header="Vorname" Width="152" Binding="{Binding firstname}" CanUserResize="False"></DataGridTextColumn>
<DataGridTextColumn Header="Nachname" Width="152" Binding="{Binding lastname}" CanUserResize="False"></DataGridTextColumn>
<DataGridTextColumn Header="Geburtstag" Binding="{Binding birthdate}" Visibility="Collapsed" CanUserResize="False"></DataGridTextColumn>
<DataGridTextColumn Header="Arbeitsstunden" Width="152" Binding="{Binding timeWorked}" CanUserResize="False"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
CodePudding user response:
The reason for that behavior is the DataGrid-Property IsHitTestVisible="False"