日期:2014-05-17  浏览次数:21066 次

|ZYCWPF| WPF中如何将ListView绑定数组呢?谢谢

            List<string[]> items = new List<string[]>();
            List<Process> listProcess = new List<Process>();
            var processes = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(this.m_fileName));
            foreach (var p in processes)
            {
                listProcess.Add(p);
                var item = new string[]{
                    p.Id.ToString(),
                    p.ProcessName,
                    string.Format("{0}KB",p.WorkingSet64/1024F),
                    p.StartTime.ToString(),
                    p.MainModule.FileName
                };
                items.Add(item);
            }
            this.ProcessListItem = items; //这里两个对像,一个是List数组
            this.ProcessList = listProcess; //这里是一个List<Process>

然后在XAML,中我可以绑定List<Process>如

        <ListView Grid.Row="0" ItemsSource="{Binding ProcessList}">
            <ListView.View>
                <GridView>
                    <GridView.Columns>
                        <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Id}" />
                        <GridViewColumn Header="ProcessName" DisplayMemberBinding="{Binding ProcessName}" />
                        <GridViewColumn Header="WorkingSet64" DisplayMemberBinding="{Binding WorkingSet64}" />
                        <GridViewColumn Header="StartTime" DisplayMemberBinding="{Binding Star