I have a problem with my ListBox I've set the ListBox selection mode to Multiple The problem is that the Selected Item fire only once, and when I select other items, it is doesn't change the SelectedItem at the view model. I'm sure its selection them because I bind a property to true when they are selected, but the selected item does not update. For example: Lets say I have ListBox with the following: A B C Choose A -> the ViewModel update the selectedItem to A Choose B -> The ViewModel doesn't update the SelectedItem but I can see that B is selected When I deselect A, the ViewModel update the SelectedItem to null Someone already faced that issue? My main goal is to keep my SelectedItem update to the one I chose He is my code for the View:
<ListBox HorizontalAlignment="Center" ItemsSource="{Binding AvailableDagrVMEs}"
SelectedItem="{Binding SelectedDagrVME}"
SelectionMode="Multiple"
VirtualizingStackPanel.IsVirtualizing="False"
ScrollViewer.HorizontalScrollBarVisibility="Auto" Padding="0" Margin="0" ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.PanningMode="HorizontalOnly"
Background="Transparent"
BorderThickness="0">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="1"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="IsSelected" Value="{Binding Taken, Mode=TwoWay}"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel>
<Image Source="{Binding Icon , Converter={StaticResource BitmapToImageSourceConverter}}"/>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
And ViewModel:
public BaseVME SelectedDagrVME
{
get { return selectedDagrVME; }
set
{
if (selectedDagrVME != value)
{
Set("SelectedDagrVME", ref selectedDagrVME, value);
}
}
}
I've tried: TwoWay binding/UpdateTriggerSource