1

嘿,所以我想知道UIElementSkype 使用什么Contact List来显示每个内容中的其他详细信息ListItem(例如Status UpdatesAvatarsOnline Status)?

Skype 列表框
(来源:iforce.co.nz

据我所知,常规System.Windows.Forms.ListBox只允许您显示一行文本来表示它Object

windows.form.listbox
(来源:iforce.co.nz

我正在寻找重新创建类似但出于不同目的的东西,但我在谷歌上找不到很多东西(所以我想看看这里是否有人有修改 a 设计的经验ListBox,以获得更好的视角在每个细节上)。

谢谢

4

1 回答 1

3

Datatemplate这是为 WPF创建自定义的一个非常基本的示例。

首先,您Model使用要显示的所有属性创建您的,然后将它们的列表绑定到您的ListBox. 然后你可以创建一个DataTemplate这基本上是你的 xaml(visual) 表示Model,你可以让它看起来像你想要的那样,你可以Model使用DataTemplate.

例子:

窗口代码:

public partial class MainWindow : Window
{
    private ObservableCollection<MyListBoxItemModel> _listBoxItems = new ObservableCollection<MyListBoxItemModel>();

    public MainWindow()
    { 
        InitializeComponent();
        ListBoxItems.Add(new MyListBoxItemModel { Title = "Item 1", Image = new BitmapImage(new Uri("http://icons.iconarchive.com/icons/custom-icon-design/mini/32/Search-icon.png")) });
        ListBoxItems.Add(new MyListBoxItemModel { Title = "Item 2", Image = new BitmapImage(new Uri("http://icons.iconarchive.com/icons/custom-icon-design/mini/32/Search-icon.png")) });
        ListBoxItems.Add(new MyListBoxItemModel { Title = "Item 3", Image = new BitmapImage(new Uri("http://icons.iconarchive.com/icons/custom-icon-design/mini/32/Search-icon.png")) });
    }

    public ObservableCollection<MyListBoxItemModel> ListBoxItems
    {
        get { return _listBoxItems; }
        set { _listBoxItems = value; }
    }
}

模型:

public class MyListBoxItemModel : INotifyPropertyChanged
{
    private string _title;
    private string _line2 = "Line2";
    private BitmapImage _image;

    public string Title
    {
        get { return _title; }
        set { _title = value; NotifyPropertyChanged("Title"); }
    }

    public string Line2
    {
        get { return _line2; }
        set { _line2 = value; NotifyPropertyChanged("Line2"); }
    }


    public BitmapImage Image
    {
        get { return _image; }
        set { _image = value; NotifyPropertyChanged("Image"); }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(string p)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(p));
        }
    }
}

xml:

   <Window x:Class="WpfApplication7.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfApplication7"
        Title="MainWindow" Height="351" Width="464" Name="UI" >

 <Window.Resources>
    <!-- The tempate for MyListBoxItemModel -->
    <DataTemplate DataType="{x:Type local:MyListBoxItemModel}">
        <StackPanel Orientation="Horizontal">
            <Image Source="{Binding Image}" />
            <StackPanel>
                <TextBlock Text="{Binding Title}" FontWeight="Medium" />
                <TextBlock Text="{Binding Line2}" />
            </StackPanel>
        </StackPanel>
    </DataTemplate>   
 </Window.Resources>

    <Grid>
        <ListBox ItemsSource="{Binding ElementName=UI, Path=ListBoxItems}" />
    </Grid>

</Window>

这只是一个带有Image和一些文本的简单示例,但它应该可以帮助您入门,只需修改DataTemplate以及Model您希望如何显示snp code数据

结果:

在此处输入图像描述

于 2013-02-18T23:55:47.357 回答