Using ArcGIS Pro SDK 3.3...
I have a bit of code that populates a combobox with options then selects the first one. The selection only works some of the time and is not predictable that I can tell. I added a Thread.Sleep(1000) and it works so this tells me it's definitely some sort of asynchronous action happening with the initial load of the combobox. I'm just wondering what the proper way to load, then select the first item would be.
Here is my code that works (with the sleep). It's overly complicated because the customer wants the currently selected location name first, then a blank line, then all of the available location names after that.
The combobox binding properties:
private ObservableCollection<OffroadLocationNames> _locationNames;
public ObservableCollection<OffroadLocationNames> LocationNames
{
get => _locationNames;
set => SetProperty(ref _locationNames, value);
}
private OffroadLocationNames _selectedLocationName;
public OffroadLocationNames SelectedLocationName
{
get => _selectedLocationName;
set => SetProperty(ref _selectedLocationName, value);
}
DockPane populate code: (I'm creating a local ObservableCollection then assigning it to the bound property just as a test to see if it made a difference... which it did not.)
var locationList = new ObservableCollection<OffroadLocationNames>();
if (!string.IsNullOrEmpty(pointData.TrafficFeature) && pointData.LocationID > 0)
{
OffroadLocationNames thisOne = Module1.Current.Cache.OffroadLocations.Data.FirstOrDefault(d => d.LocationId == pointData.LocationID);
if (thisOne != null)
{
locationList.Add(thisOne);
locationList.Add(new OffroadLocationNames() { LocationId = -1, LocationName = "" });
}
locationList.AddRange(Module1.Current.Cache.OffroadLocations.GetUnusedLocationNames(pointData.TrafficFeature));
LocationNames = new ObservableCollection<OffroadLocationNames>(locationList);
Thread.Sleep(1000);
SelectedLocationName = LocationNames.First(); // OrDefault(ln => ln.LocationId == thisOne.LocationId);
}