I have an Image inside an ItemTemplate for a ListBox. Is there a way in XAML to toggle its visibility based on the ListBox’ SelectedItem?
In other words, I want the image to be visible only if the ListBoxItem is selected, but want to avoid code-behind for that.
Thanks.
Edit the ListBox’s ItemContainerStyle, and you will then have access to all the States for the ListBox items. These include the focussed and selected states. If you’re doing this in Blend, it should be under “Edit Additional Templates” on the ListBox’s context menu.
Then you should be able to change the layout for the Selected state, which should be what you need?