I publish a list of objects in a ListBox and hoped to bind the selection of an item to a boolean property.
<ListBox x:Name="DataLayerList" SelectionMode="Extended" IsTextSearchEnabled="True" ItemsSource="{Binding LayersFiltered, Mode=OneWay}">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="IsSelected" Value="{Binding ListItemSelected, Mode=TwoWay}"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
LayersFiltered is a list of ThemeLayer, where Theme layer is defined as such.
public class ThemeLayer
{
public readonly string Name;
public readonly string Id;
public readonly string Type;
public override string ToString()
{
return Name;
}
public ThemeLayer(string name, string id, string type)
{
Name = name;
Id = id;
Type = type;
}
public bool IsSelected { get; set; }
}
Within my ViewModel LayersFiltered and ListItemSelected are defined as:
private List<ThemeLayer> _layersFiltered;
public List<ThemeLayer> LayersFiltered
{
get => _layersFiltered;
set => SetProperty(ref _layersFiltered, value, () => LayersFiltered);
}
private bool _listItemSelected;
public bool ListItemSelected
{
get => _listItemSelected;
set
{
SetProperty(ref _listItemSelected, value, () => ListItemSelected);
}
}
However, ListItemSelected is never triggered when I select a ListBoxItem.
I had a look at https://github.com/Esri/arcgis-pro-sdk-community-samples/blob/44183d0d5a9bc5da6fb8b9229211cc707dd2b874/Framework/RemoveAddins/SampleBackstageTabView.xaml but fail to transfer it into my code.