GuOrg / Gu.Wpf.UiAutomation

MIT License
96 stars 17 forks source link

DataGrid.RowCount: Exception when ItemSource is empty collection #46

Closed FoggyFinder closed 6 years ago

FoggyFinder commented 6 years ago

DataGrid.RowCount throws InvalidOperationException here when ItemSource is empty collection.

public override T GetItem<T>(int row, int column, Func<BasicAutomationElementBase, T> wrap)
{
    var nativeItem = Com.Call(() => this.NativePattern.GetItem(row, column));
    if (nativeItem == null)
    {
        throw new InvalidOperationException("Did not find item.");
    }

    return wrap(new UIA3BasicAutomationElement((UIA3Automation)this.BasicAutomationElement.Automation, nativeItem));
}

If set CanUserAddRows="False" it works fine.

JohanLarsson commented 6 years ago

We should probably spexialcase it, not sure what is best, maybe just write the simplest we can come up with and throw some tests at it?