0

I have a ListView to which item source is given from the viewModel. On a button click the selected items will be changed. Now the problem is, the previous item of Listview is displaying as selected. When I observed, the selected item is set to the expected value but the anchor item is having previously selected Item. I am suspecting that due to the anchor Item the item is displaying as selected.

enter image description here

In the above screenshot, test t2 is currently selected one Test t3 is the anchor item, which I have selected previously.

here is my listView

<ListView Grid.Row="2" x:Name="AllUsers" ItemsSource="{Binding Source={StaticResource Users}}"
                      HorizontalAlignment="Stretch" Cursor="Hand" AllowDrop="False" ForceCursor="True" MouseLeftButtonUp="OnUsersSelected"
                      VerticalAlignment="Top" ScrollViewer.HorizontalScrollBarVisibility="Disabled" >
                    
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            // Some code
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

Can someone help me to fix this, please.

sahithi
  • 1,039
  • 2
  • 14
  • 37
  • Do you mean that item is focused? Do you have focused style in the datatemplate? You can override item template and bind select stylings. – Ievgen Sep 15 '20 at 17:36
  • Yes @IevgenNaida – sahithi Sep 15 '20 at 17:37
  • https://stackoverflow.com/questions/146269/change-wpf-datatemplate-for-listbox-item-if-selected – Ievgen Sep 15 '20 at 17:39
  • If you don't need some functionally from the item template: focused, selected. You can override item template and turn off those features – Ievgen Sep 15 '20 at 17:40
  • Thanks, @Ievgen Naida, I will try this approach. – sahithi Sep 15 '20 at 17:45
  • No Luck @IevgenNaida, still the view is the same as in the screenshot. Am I missing anything, I am actually looking for-> If any other item is selected, the only currently selected item should be highlighted. – sahithi Sep 15 '20 at 18:05
  • But solution is still the same. You should override not a data template but a style and disable default focus and selection styling. also you can control completely styling of selected items https://stackoverflow.com/questions/2282138/wpf-listview-selecting-multiple-list-view-items – Ievgen Sep 16 '20 at 06:57

0 Answers0