I have a listbox representing a SQL WHERE statement and the items inside can be grouped.
For example, a user can have the following items in their ListBox
I would like to show the AND/OR value only if the ListBox item is not the first item in the listbox or a group (like example). I am currently using a MultiConverter on the ListBox's ItemTemplate that accepts the ListBox's ItemSource and the Current Item as parameters, however existing items do not get their AND/OR visibility updated when the user adds a new item, or drags an existing item to a new spot in the listbox.
Is there a way to tell the MultiConverter to reevaluate when one of its parameters, the ListBox's ItemSource, changes? I am using MVVM and the ListBox is bound to an ObservableCollection of items.
Update Code as requested by Adam...
<ListBox x:Name="WhereList" ItemsSource="{Binding Path=CurrentQuery.WhereList}">
<ListBox.Style>
<Style TargetType="{x:Type ListBox}">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch"
Margin="{Binding Path=Depth, Converter={StaticResource QueryBuilder_DepthToMarginConverter}}">
<Label Content="{Binding Path=BooleanComparison}" Padding="0">
<Label.Visibility>
<MultiBinding Converter="{StaticResource ShouldShowOperatorConverter}">
<Binding ElementName="WhereList" Path="ItemsSource"/>
<Binding />
</MultiBinding>
</Label.Visibility>
</Label>
<Label Content="{Binding ConditionText}" Padding="0" HorizontalAlignment="Stretch" />
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.Style>
</ListBox>
The MultiConverter accepts a list of items, and the current item. It checks to see if the item is the first item in the list, or if the previous item in the list is a GroupStart item. If either of these conditions are true, it returns Visibility.Collapsed, otherwise it returns Visibility.Visible.
It works fine for the first load, and changes made to a single item (dragging a new item into the listbox, or dragging an existing item to a new location in the listbox) will correctly update the new item's AND/OR visibility, however it does not change any other item then the one being added/moved. So if you drag a new item to the top of the list, it will correctly hide the AND/OR of the new item, however it will not update the 2nd item (former first item) to show the AND/OR. This really affects the readability of the items in the list and prevents the user from seeing if they are currently linking the item with an AND or an OR which makes a big difference in the results returned.
I'm fairly sure it has something to do with the fact I'm using a MultiConverter since my DepthToMarginConverter works fine (for example, grouping items correctly updates the margin of all items within the group).