I'm developing a DockPane Add-In that makes searching our API of imagery easy. In short, a Search button is clicked (which issues an ICommand), the search results are retrieved asynchronously from our API and added to a collection bound to a ListView, and an overview geometry graphic is added to the map's GraphicsLayer.
The issue I'm running into is that I want the mouse cursor to be spinning until the ListView is fully re-rendered and the GraphicsLayer is displays the graphic. I thought this would be as simple as awaiting the async steps (API call and the QueuedTask that renders the graphic), but what's currently happening is that the Cursor resets to Default seemingly after the API responds, long before the ListView re-renders and even longer before the GraphicsLayer is updated, especially when hundreds or thousands of results are fetched.
I'm familiar with async/await in JS and Rust, but am pretty new to C#/WPF apps and even newer to ArcGIS Pro SDK so I might be missing the option to await some events or Task configuration.
Is there any way I can create the desired UI experience?
// the ICommand.Action that is executed on button click
private async void DoSearch()
{
// Set the cursor to spin, signalling to the user that background work is being done
Cursor.Current = Cursors.WaitCursor;
// an ObservableCollection, bound to a ListView in the DockPane
SearchResults = await StacClient.Instance.SearchItemsEx(request);
// add search results footprint graphic
await QueuedTask.Run(() =>
{
graphicsLayer.RemoveElements(graphicsLayer.GetElements());
if (SearchResults.Count > 0)
{
graphicsLayer.AddElement(new CIMPolygonGraphic
{
Name = "Search Result Overview",
Symbol = DefaultPolySymbolRef,
Transparency = DefaultTransparency,
Polygon = GeometryEngine.Instance.Union(SearchResults.Select(res => res.geometry)) as Polygon,
});
}
});
// Set the cursor back to the default, signalling the end of search and render
Cursor.Current = Cursors.Default;
}