简体   繁体   中英

ListView Multibinding?

Me and a friend are creating our own skype"ish" application as a fun little project.

We've now reached the point where we'd like to create a list of contacts.

Each of our contacts contains this:

<ListView Grid.Column="0" x:Name="ContactList" BorderBrush="#FF252525" ScrollViewer.HorizontalScrollBarVisibility="Hidden"
              ScrollViewer.VerticalScrollBarVisibility="Hidden" Grid.Row="0" Grid.RowSpan="3" ItemsSource="{Binding Path=ContactNameList}">
        <ListView.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <Grid>
                        <TextBlock Text="NameOfContact" Padding="7,5,0,10" FontSize="16" />
                        <TextBlock Text="JobTitle" Padding="7,25,0,0" FontStyle="Italic" Foreground="#FF8D8D8D" />
                        <Ellipse Fill="#FF00FF00" Width="14" Height="14" Margin="132,18,14,18" HorizontalAlignment="Right" />
                    </Grid>
                </StackPanel>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

But here is the problem, we have 3 observablecollections

  • ContactNameList
  • ContactTitleList
  • ContactStatusList

Now, I know how to make a simple binding, but I don't know how to make 3 bindings to one ListView. I've seen some of examples of Multibindings but couldn't really find one where it showed how to set up the sources (the data that is supposed to show up).

So the question is, how could I make the template look like this? (Theoretical binding of course!):

<ListView Grid.Column="0" x:Name="ContactList" BorderBrush="#FF252525" ScrollViewer.HorizontalScrollBarVisibility="Hidden"
              ScrollViewer.VerticalScrollBarVisibility="Hidden" Grid.Row="0" Grid.RowSpan="3" ItemsSource="{Binding Path=ContactNameList,ContactTitleList,ContactStatusList}">
        <ListView.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <Grid>
                        <TextBlock Text="{Binding Path=ContactNameList}" Padding="7,5,0,10" FontSize="16" />
                        <TextBlock Text="{Binding Path=ContactTitleList}" Padding="7,25,0,0" FontStyle="Italic" Foreground="#FF8D8D8D" />
                        <Ellipse Fill="#FF00FF00" Width="14" Height="14" Margin="132,18,14,18" HorizontalAlignment="Right" />
                    </Grid>
                </StackPanel>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

For anyone wondering, this is how the contacts will show up. All I really want is for the text and eclipse to chance corresponding to their list.

EDIT: To @Kirenenko

public class ContactsClass : INotifyPropertyChanged {

    public ContactsClass() {

    }

    public ObservableCollection<ContactsClass> contacts = new ObservableCollection<ContactsClass>();

    string[] Name = new string[2];
    string[] Title = new string[2];
    string[] Status = new string[2];

    public event PropertyChangedEventHandler PropertyChanged;
}

I believe what you should have is not three lists, but a list which has all the related info of a user in its nodes.

Like:

<users>
<user>
<ContactName></ContactName>
<ContactTitle></ContactTitle>
<ContactStatus></ContactStatus>
</user>
</users>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM