I recently upgraded ArcGIS Pro and Visual Studio SDK Extensions to version 3.2.2, coming across a very strange behavior, which wasn't present in version 3.1
I have a ProWindow with several controls and logic in it, with MVVM pattern. One control is a datagrid which shows some business data in a pretty simple configuration:
<DataGrid Grid.Row="0" x:Name="dgBeni" ScrollViewer.CanContentScroll="True"
Margin="0,5,0,0"
VerticalAlignment="Top"
Style="{DynamicResource Esri_DataGrid}"
AutoGenerateColumns="False"
HeadersVisibility="Column"
RowHeaderWidth="0"
IsReadOnly="True"
Height="250"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
SelectionMode="Single"
ItemsSource="{Binding Path=CurrentItem.Beni}"
SelectedItem="{Binding Path=CurrentItem.SelectedBene}">
<DataGrid.Columns>
<DataGridTextColumn Header="Cod Bene" Binding="{Binding CODBASE}" IsReadOnly="True" Width="Auto"></DataGridTextColumn>
<DataGridTextColumn Header="SubCod" Binding="{Binding SUBCOD_LIST}" IsReadOnly="True" Width="Auto"></DataGridTextColumn>
<DataGridTextColumn Header="Stato" Binding="{Binding STATOBENE}" IsReadOnly="True" Width="Auto"></DataGridTextColumn>
<DataGridTextColumn Header="Descrizione" Binding="{Binding DESCBENE}" IsReadOnly="True" Width="*"></DataGridTextColumn>
</DataGrid.Columns>
<Behaviors:Interaction.Triggers>
<Behaviors:EventTrigger EventName="SelectionChanged">
<Behaviors:InvokeCommandAction Command="{Binding dgBeni_SelectionChangedCommand}" />
</Behaviors:EventTrigger>
</Behaviors:Interaction.Triggers>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{x:Null}" />
<Setter Property="BorderBrush" Value="{x:Null}" />
</Trigger>
<DataTrigger Binding="{Binding IsLocal}" Value="false">
<Setter Property="Foreground" Value="Red"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsLocal}" Value="true">
<Setter Property="Foreground" Value="Blue"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
</DataGrid>
Datagrid binds its ItemSource and SelectedItem properties, plus it binds the SelectionChanged event to a command via Interaction Trigger.
The code behind of the command is pretty simple stuff as well:
public ICommand dgBeni_SelectionChangedCommand => new RelayCommand(async () =>
{
if (CurrentItem.SelectedBene is null || CurrentItem.SelectedBene.OID <= 0)
return;
var LayerBeni = MapView.Active.Map.FindLayers(Constants.LayerNames.Beni).OfType<FeatureLayer>().FirstOrDefault();
//ZoomTo - IT BREAKS COMMAND BINDING
await MapView.Active.ZoomToAsync(LayerBeni, CurrentItem.SelectedBene.OID, new TimeSpan(0, 0, 1));
//Flash
var selectionDictionary = new Dictionary<MapMember, List<long>>() { { LayerBeni, new List<long>() { CurrentItem.SelectedBene.OID } } };
SelectionSet selectionToFlash = SelectionSet.FromDictionary(selectionDictionary);
MapView.Active.FlashFeature(selectionToFlash);
}, () => true);
It is supposed to get the feature identified by the selected row and zoom+flash to it.
This worked just fine in 3.1 but after the upgrade it works only once (for the first selection) and after that the command is not triggered again (unless I close the ProWindow and open it again). It took me a while to understand that the actual thing the "breaks" the event is the call to ZoomToAsync(). If I just omit the line, it works as intended and the event is raised at every selection change.
As I debugged this I managed to find some more details about the bug:
- The issue is the same using the synchronous ZoomTo() function as well (removing the async mark from the anonymous function in the RelayCommand and calling ZoomTo() within a QueuedTask() call produces the same result)
- It seems to affect any event command binding (I also tried to work with some mouse-related events to bypass the issue, but they all break in the same way)
Currently I couldn't find any workaround to bypass this, without changing the UI. The only solution that comes to my mind would be to separate apart selection and zoom+flash operations, for instance exposing a button that triggers the action after row selection on the datagrid: it should work, but I can't change UI in such way so for now I just skip zooming.
I believe this is an actual bug of the SDK but in case anyone will come across this issue and finds some solution please let me know.