0

I am still new to MVVM (and C#) so please let me know if my question is unclear and I will update/clarify.

I have a ListView in my xaml with the following code:

<ListView.Resources>
    <local:IndexConverter x:Key="IndexConverter" />
    <DataTemplate x:Key="OrdinalColumnDataTemplate">
        <TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListViewItem},
        Converter={StaticResource ResourceKey=IndexConverter}}" HorizontalAlignment="Right" />
    </DataTemplate>
</ListView.Resources>

<ListView.View>
    <GridView x:Name="gridView3">
        <GridViewColumn Header="#" CellTemplate="{StaticResource ResourceKey=OrdinalColumnDataTemplate}" />
        <GridViewColumn DisplayMemberBinding="{Binding Name, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}" Header="Name" />
        <GridViewColumn DisplayMemberBinding="{Binding License, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}" Header="License" />
    </GridView>
</ListView.View>

It works as expected, It is populated with Name and License attributes of each element. Now I would like to add a ComboBox and populate it with the unique Names of the same element which are shown in the ListView.

QUESTION 1: I have tested the below code but it does not work, how should the xml look like?

<ComboBox Name="filterUserComboBox" ItemsSource="{Binding Path=licenseListView, ElementName=Name}"></ComboBox>

QUESTION 2: When the above works properly, how do I add an 'all' (or a single empty element) element to the ComboBox?

theAlse
  • 5,577
  • 11
  • 68
  • 110

1 Answers1

0

Ok, I managed to solve both questions myself. Hope it might help people in the future.

ANSWER 1: Turned out the xml was just a litte bit off.

<ComboBox Name="filterUserComboBox" ItemsSource="{Binding Path=ResourceList}" DisplayMemberPath="Name"></ComboBox>

ANSWER 2: I researched this a long while and the solution is to actually change the MVVM which is populated in the ComboBox, so the source should actually include an empty/all option to be shown in the ComboBox.

theAlse
  • 5,577
  • 11
  • 68
  • 110