简体   繁体   English

ListView多绑定?

[英]ListView Multibinding?

Me and a friend are creating our own skype"ish" application as a fun little project. 我和一个朋友正在创建我们自己的skype“ ish”应用程序,这是一个有趣的小项目。

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 但这是问题所在,我们有3个可观察的集合

  • ContactNameList 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. 现在,我知道如何进行简单的绑定,但是我不知道如何对一个ListView进行3个绑定。 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). 我已经看到了一些Multibindings的示例,但实际上找不到一个显示如何设置源(应该显示的数据)的示例。

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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