【问题标题】:What System.Windows UIElement does skype use for its 'Contact List'?Skype 将什么 System.Windows UIElement 用于其“联系人列表”?
【发布时间】:2013-02-18 23:04:08
【问题描述】:

嘿,所以我想知道 UIElement 为它的 Contact List 使用了什么 Contact List 以便在每个 ListItem 中显示更多详细信息(例如 Status UpdatesAvatarsOnline Status 等等)?


(来源:iforce.co.nz

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


(来源:iforce.co.nz

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

谢谢

【问题讨论】:

  • 您确定、绝对确定 Skype 在您的平台上使用 WPF?
  • 我不确定,这就是我问的原因。我认为这可能吗?但实际上我不确定。
  • @Killrawr: 1. Delphi 2. 绝对是自定义控件。实现自定义控件实际上并不罕见,尤其是当您是 Skype 程序员时
  • 这根本不是“修改设计”,而是从头开始实现一个全新的控件。
  • 你可以创建自己的ListBoxItem,在任何你想要的地方都有图像和标签,很简单,你在寻找 WPF 或 Winforms 的例子,我不介意模仿一个

标签: c# wpf user-interface skype uielement


【解决方案1】:

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

首先,您使用您想要显示的所有属性创建您的Model,然后将它们的列表绑定到您的ListBox。然后您可以创建一个DataTemplate,这基本上是您的Model 的xaml(可视)表示,您可以让它看起来像您想要的那样,您可以使用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));
        }
    }
}

Xaml:

   <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 和一些文本的简单示例,但它应该可以帮助您入门,只需修改DataTemplateModel 您希望如何显示snp code 数据

结果:

【讨论】:

  • 嘿,谢谢,您知道如何在Text="" Setter 中添加&lt;LineBreak /&gt; 吗?
  • LineBreak 是什么意思?新队?您可以只添加一个新的 TextBlocl 或在现有的 TextBlock 上使用 MutiBinding
  • 您介意用MultiBinding 的示例更新答案吗? (要显示一个项目,例如Item 2.1 Underneth Item 2)。再次感谢! :)
  • 更新了数据模板和模型以在 TextBlock 上显示 MultiBinding
  • 嗨 sa_ddam213,非常感谢。我想知道你如何区分Item 2Item 2.1 之间的样式?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-23
  • 2021-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多