自定义的ListViewItem ListView中 [英] Custom ListViewItem in ListView

查看:106
本文介绍了自定义的ListViewItem ListView中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的方式ListViewItem的显示项的 WPF

possible ways to show item in ListViewItem WPF

更新:

Update:

这是我需要添加到ListView,这里我只需要显示的计算机名称,还是该项目需要在按住电脑地址控制

that's the control i need to add to the ListView, in here i only need to display the Computer Name, still the item should hold the Computer Address

之后,我将需要与重新present文件和文件夹的项目的ListView这将有:名称,路径,大小,图标,ISFILE性能

later, i will need ListView with Items that represent Files and Folders which will have : Name, Path, Size, Icon, IsFile properties.

所以这就是我正在处理,现在,陷在其中的ListView我没想到会发生在我切换到WPF IM

so this's what I'm dealing with right now, im stuck in listView which i didn't expect to happen when i switched to WPF

推荐答案

下面是另外一个例子:

<Window x:Class="WpfApplication14.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
    <DockPanel>
        <Button Content="Show Selected Computer" Click="Button_Click" DockPanel.Dock="Top"/>

        <ListBox ItemsSource="{Binding}"
                 SelectedItem="{Binding SelectedComputer, RelativeSource={RelativeSource AncestorType=Window}}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <DockPanel Margin="2">
                        <Rectangle Fill="Gray" Width="32" Height="32" DockPanel.Dock="Left"/>
                        <TextBlock Text="{Binding Name}" VerticalAlignment="Center"/>
                    </DockPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </DockPanel>
</Window>

code背后:

Code Behind:

public partial class Window1 : Window
{
    public Window1()
    {
        InitializeComponent();

        DataContext = Enumerable.Range(1,10)
                                .Select(x => new ComputerInfo()
                                {
                                    Name = "Computer" + x.ToString(),
                                    Ip = "192.168.1." + x.ToString()
                                });

    }

    public ComputerInfo SelectedComputer { get; set; }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        MessageBox.Show(SelectedComputer.Ip);
    }
}

数据项:

public class ComputerInfo
{
    public string Name { get; set; }
    public string Ip { get; set; }
}

结果:

这篇关于自定义的ListViewItem ListView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆