MaterialDesignInXamlToolkit icon indicating copy to clipboard operation
MaterialDesignInXamlToolkit copied to clipboard

Datagrid ArgumentOutOfRangeException

Open jbooth88 opened this issue 3 years ago • 0 comments

Bug explanation

I have a view model structure (simplified) as follows:

public sealed class Parent
{
    public ReadOnlyObservableCollection<Child> Children { get; init; }
    public bool IsSelected { get; set; }
}
public sealed class Child 
{
    public Parent MyParent { get; init; }

    public bool IsSelected { get; set; }
}

I have xaml for a DataGrid as follows (simplified version):

<DataGrid 
    ItemsSource="{Binding Parents, IsAsync=True}" 
    AutoGenerateColumns="False"
    RowDetailsVisibilityMode="Visible"
    >
    <DataGrid.Columns>
        <DataGridCheckBoxColumn Header="IsSelected" Binding="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsThreeState="False" SortMemberPath="IsSelected" IsReadOnly="False" />
        <DataGridTextColumn Header="Parent ID" Binding="{Binding Path=., Mode=OneTime}" SortMemberPath="DisplayName" IsReadOnly="True" />
    </DataGrid.Columns>
    <DataGrid.RowDetailsTemplate>
        <DataTemplate>
            <DataGrid 
                ItemsSource="{Binding Children, Mode=OneTime}"
                AutoGenerateColumns="False"
                >
                <DataGrid.Columns>
                    <DataGridCheckBoxColumn Header="IsSelected" Binding="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsThreeState="False" SortMemberPath="IsSelected" IsReadOnly="False" />
                    <DataGridTextColumn Header="Child ID" Binding="{Binding Path=., Mode=OneTime}" SortMemberPath="DisplayName" IsReadOnly="True" />
                </DataGrid.Columns>
            </DataGrid>
        </DataTemplate>
    </DataGrid.RowDetailsTemplate>
</DataGrid>

AllowDirectEditWithoutFocus(object sender, System.Windows.Input.MouseButtonEventArgs mouseArgs) is throwing an ArgumentOutOfRangeException when the user clicks the check box of any DataGrid that resides inside a row details template

Setting the DataGrid style to null or using EnableEditBoxAssist=False prevents the exception.

Version

4.5.0

jbooth88 avatar Sep 15 '22 23:09 jbooth88