MaterialDesignInXAML / MaterialDesignInXamlToolkit

Google's Material Design in XAML & WPF, for C# & VB.Net.
http://materialdesigninxaml.net
MIT License
15.11k stars 3.42k forks source link

DataGrid unintuitive behaviour #2722

Closed ThatGuyMike7 closed 1 year ago

ThatGuyMike7 commented 2 years ago

Bug explanation

When I click twice on a field, its entire row becomes grey and my clicks on the field are ignored (can't edit the value), until I click on another field in another row. It seems to be very unintuitive.

I don't expect two clicks on a field to result in not being able to edit that field anymore.

I use the DataGrid like this:

<Grid>
    <TabControl TabStripPlacement="Top">
        <TabItem Header="Produkte" MaxWidth="10000">
            <StackPanel Orientation="Vertical">
                <ScrollViewer Height="300" Margin="10">
                    <DataGrid x:Name="ProductDataGrid" MinColumnWidth="50" ItemsSource="{Binding ProductData}"></DataGrid>
                </ScrollViewer>
            </StackPanel>
        </TabItem>
    </TabControl>
</Grid>

Version

4.5.0

ElieTaillard commented 2 years ago

I noticed the same behavior in the Demo App.

We have to clic outside the textbox do be able to edit the cell.

https://user-images.githubusercontent.com/54487782/170958020-53f7b14e-71bb-4ff9-a289-41cfb7909621.mp4

soi013 commented 2 years ago

I had the behavior in my app. I found a workaround. Set the Focusable of the ScrollViewer above the DataGrid to False.

<ScrollViewer 
   Focusable="False">
...
   <DataGrid>
...

In the Demo App, I fix this line. https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/a4a5cd21e328ce1e473811ad330a40e5f9ac1d55/MainDemo.Wpf/MainWindow.xaml#L220

However, I am not sure what the cause is.

jbooth88 commented 2 years ago

I think setting DataGridAssist.EnableEditBoxAssist="False" resolves the issue? Unfortunately it re-establishes the double-click to edit (default) behaviour.

My uneducated guess would be that the AllowDirectEditWithoutFocus() method appears to work the first time when clicking directly on an element inside a datagrid cell, but won't work again unless the user either clicks outside of the contained element but still in the target cell, OR they click on another element in a different row.

Please confirm.

nicolaihenriksen commented 2 years ago

@jbooth88 I think you are right about the AllowDirectEditWithoutFocus() being the culprit. I have added a very simple PR which simply bails out of that method in case the cell is already being edited. I think this is what the user would want.

@Xaalek Could you test it out using the code from the PR (see above)?

ElieTaillard commented 2 years ago

It's better than before but we still have something weird. Depending on where we click on the cell the behavior is different. I also noticed something weird with the style MaterialDesignDataGridTextColumnPopupEditingStyle. To open the edition we have to click on the edge of the cell. Moreover the pop up doesn't open at the right place. https://youtu.be/pWXAf7tRK1Q

Unfortunately, there are no specs for editable datagrids. However, we could be inspired by this library to do the job https://mui.com/x/react-data-grid/ (especially for the style with the pop up)

nicolaihenriksen commented 2 years ago

@Xaalek I just played around with the DataGrid a bit more, and wow it really does have some strange behaviors!

I cannot reproduce the issue with the popup editing being misplaced. It opens fine on mine. I can however reproduce a bunch of different scenarios where the clicks are ignored or do not do what you would want them to.

Those issues were there before the fix in my PR, which only addresses the problem listed in this issue (i.e. the double click to edit was not working). So I guess that should not prevent the PR from being merged (you did say that "it's better than before").

Perhaps we should create another issue for sorting out the strange behaviors of the DataGrid in general?

nicolaihenriksen commented 1 year ago

@Xaalek I think this was - for the most part - fixed in the latest release? Should we close the issue?

nicolaihenriksen commented 1 year ago

@ThatGuyMike7 Can you reproduce the issue with the latest release? If not, perhaps the issue should be closed?

ElieTaillard commented 1 year ago

Looks good to me. I just have the popup issue that is still there.