I’m using the following (simplified) code to display an element in all the items in an ItemsControl except the first:
<TheElement Visibility="{Binding RelativeSource={RelativeSource PreviousData},
Converter={StaticResource NullToVisibility}}/>
NullToVisibility is a simple converter that returns Visibility.Hidden if the source is null, Visibility.Visible otherwise.
Now, this works fine when binding the view initially, or adding elements to the list (an ObservableCollection), but the element is not made invisible on the second element when removing the first.
Any ideas on how to fix this?
Had some wasted code leftover from a previous answer… might as well use it here:
The key is to refresh the viewsource e.g. :
Full example source below. Remove First Item removes first element and refreshes the view:
RelativeSourceTest.xaml
RelativeSourceTest.xaml.cs
Category.cs