Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ public partial class ListView : Control
// We cache the NewWidth supplied by the user and use it on HDN_ENDTRACK to set the final column width.
private int _newWidthForColumnWidthChangingCancelled = -1;

// Tracks ListViewItems that have had their AccessibilityObject created in virtual mode,
// so their UIA providers can be properly released later without triggering item retrieval
private readonly HashSet<ListViewItem> _uiaCreatedItems = [];

/// <summary>
/// Creates an empty ListView with default styles.
/// </summary>
Expand Down Expand Up @@ -5084,16 +5088,43 @@ public void RedrawItems(int startIndex, int endIndex, bool invalidateOnly)
}
}

internal void NotifyUiaCreated(ListViewItem item)
{
if (VirtualMode)
{
_uiaCreatedItems.Add(item);
}
}

internal override void ReleaseUiaProvider(HWND handle)
{
if (!OsVersion.IsWindows8OrGreater())
{
return;
}

for (int i = 0; i < Items.Count; i++)
if (VirtualMode)
{
Items.GetItemByIndex(i)?.ReleaseUiaProvider();
foreach (ListViewItem item in _uiaCreatedItems)
{
if (item.IsAccessibilityObjectCreated)
{
item.ReleaseUiaProvider();
}
}

_uiaCreatedItems.Clear();
}
else
{
for (int i = 0; i < Items.Count; i++)
{
var item = Items.GetItemByIndex(i);
if (item?.IsAccessibilityObjectCreated == true)
{
item.ReleaseUiaProvider();
}
}
}

if (_defaultGroup is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,12 @@ internal virtual AccessibleObject AccessibilityObject
};
}

owningListView.NotifyUiaCreated(this);
return _accessibilityObject;
}
}

private bool IsAccessibilityObjectCreated => _accessibilityObject is not null;
internal bool IsAccessibilityObjectCreated => _accessibilityObject is not null;

/// <summary>
/// The font that this item will be displayed in. If its value is null, it will be displayed
Expand Down