XAML ListView - Change Image Source for selected item

前端 未结 2 942
小鲜肉
小鲜肉 2021-01-23 18:40

I\'m using a ListView with a Custom Template, something like this:


    
        

        
2条回答
  •  被撕碎了的回忆
    2021-01-23 19:17

    You can create a style for your ListViewItem, with a controltemplate for the triggers and a datatemplate for your data binding, like this:

       
    

    Then configure your ListView like this:

    
    

    You'll see that the style has an EventSetter: its purpose is to get the correct item selected even if you click inside some control (not directly on the background). You need to create the handler in code behind, just a couple of lines:

        private void OnListBoxItemContainerFocused(object sender, System.Windows.RoutedEventArgs e)
        { (sender as ListViewItem).IsSelected = true; }
    

    Hope this is helpful, regards!

提交回复
热议问题