Home > database >  WPF datagrid cursor doesn't change on column resize
WPF datagrid cursor doesn't change on column resize

Time:11-13

I have encoutnered a bug that I can't make the source out of, so I wanted to ask if anyone has encountered something similar. The setup is simply:

        <Grid>
            <DataGrid>
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Test1" Width="100"/>
                    <DataGridTextColumn Header="Test2" Width="100"/>
                    <DataGridTextColumn Header="Test3" Width="100"/>
                </DataGrid.Columns>
            </DataGrid>
        </Grid>

There of course is more code after the datagrid, but at no point I implement any Styles or Themes or interact with the datagrid in any way, shape or form and it would be to much code to include it all. When I hover over the split line between columns then the mouse cursor doesn't change to the resize cursor with the 2 arrows (Cursors.SizeWE). It still works and resizes fine if I click and drag and works as expected in any other regard.

In this setup I have a style, but only for my button and here it just can't be resized at all:

<Grid x:Name="grid_main" Height="Auto" Width="Auto" Background="White">
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="40"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>


        <DataGrid Grid.Row="1">
            <DataGrid.Columns>
                <DataGridTextColumn Header="Test1" Width="100"/>
                <DataGridTextColumn Header="Test2" Width="100"/>
                <DataGridTextColumn Header="Test3" Width="100"/>
            </DataGrid.Columns>
        </DataGrid>

        <DockPanel Width="Auto" Height="Auto">
            <Button x:Name="btn_loadSchema" Content="Load Schema" Grid.Row="0" Height="20" Width="85" DockPanel.Dock="Left" 
                        Margin="5" Click="LoadSchema" Style="{StaticResource ModernButtonTheme}"/>
            <Button x:Name="btn_loadJSON" Content="Load JSON" Grid.Row="0" Height="20" Width="85" DockPanel.Dock="Left"
                        Margin="5" Click="LoadJSON" Style="{StaticResource ModernButtonTheme}" IsEnabled="False"/>
            <Button x:Name="btn_saveJSON" Content="Save JSON" Grid.Row="0" Height="20" Width="85" DockPanel.Dock="Left"
                        Margin="5" Click="SaveJSON" Style="{StaticResource ModernButtonTheme}" IsEnabled="False"/>
            <Label/>
        </DockPanel>

        <ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
            <Grid x:Name="grid_content" Height="Auto" Width="Auto">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            </Grid>
         </ScrollViewer>
    </Grid>

CodePudding user response:

Did you try to copy your first XAML snippet into a blank WPF project? Can you reproduce the issue then? I doubt it because I cannot.

As for your second snippet, you should either remove the ScrollViewer or move it to another row by adding another RowDefinition to the Grid and increase the value of Grid.Row attached property. Currently, it lays on top of the DataGrid.

Try this:

<Window ...>
    <Grid x:Name="grid_main" Height="Auto" Width="Auto" Background="White">
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="40"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>


        <DataGrid x:Name="dg" Grid.Row="1">
            <DataGrid.Columns>
                <DataGridTextColumn Header="Test1" Width="100"/>
                <DataGridTextColumn Header="Test2" Width="100"/>
                <DataGridTextColumn Header="Test3" Width="100"/>
            </DataGrid.Columns>
        </DataGrid>

        <DockPanel Width="Auto" Height="Auto">
            <Button x:Name="btn_loadSchema" Content="Load Schema" Grid.Row="0" Height="20" Width="85" DockPanel.Dock="Left" 
                        Margin="5" />
            <Button x:Name="btn_loadJSON" Content="Load JSON" Grid.Row="0" Height="20" Width="85" DockPanel.Dock="Left"
                        Margin="5" IsEnabled="False"/>
            <Button x:Name="btn_saveJSON" Content="Save JSON" Grid.Row="0" Height="20" Width="85" DockPanel.Dock="Left"
                        Margin="5" IsEnabled="False"/>
            <Label/>
        </DockPanel>
    </Grid>
</Window>
  • Related