首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在不冻结的情况下将IList与多个项目绑定到数据网格上

问如何在不冻结的情况下将IList与多个项目绑定到数据网格上
EN

Stack Overflow用户
提问于 2011-07-03 09:11:34
回答 2查看 865关注 0票数 0

嗨,我将txt文件解析为List,然后将这个集合绑定到WPF数据控件。

Txt文件包含18 000 - 19 000行。这里是这个txt文件的示例。

代码语言:javascript
复制
910839320   Hovory vo VPS   24.05.2011 08:52    0910839253  VPS     STÁLA   00:01:03            0,0488  
910839320   Hovory vo VPS   26.05.2011 10:01    0910839267  VPS     STÁLA   00:01:00            0,0465  
910839320   Hovory vo VPS   26.05.2011 10:04    0910839263  VPS     STÁLA   00:00:19            0,0147

我用这个函数将文本文件解析为IList。

代码语言:javascript
复制
    public class Call
    {
        public string Number { get; set; }
        public string CallType { get; set; }
        public string Dt { get; set; }
        public string CallingNumber { get; set; }
        public string VoiceNetwork { get; set; }
        public string Type { get; set; }
        public string TalkTime { get; set; }
        public string Price { get; set; }
    }

    private static IEnumerable<Call> Parse(string path)
    {
        var calls = new List<Call>();

        string[] lines = System.IO.File.ReadAllLines(path);

        for (int i = 0; i < lines.Length; i++)
        {
            string[] line = lines[i].Split('\t');

            var call = new Call
                           {
                               Number = line[0],
                               CallType = line[1],
                               Dt = line[2],
                               CallingNumber = line[3],
                               VoiceNetwork = line[4],
                               Type = line[6],
                               TalkTime = line[7],
                               Price = line[10]
                           };
            calls.Add(call);
        }

        return calls;
    }

解析是可以的。

问题是,如果我尝试将mehod分析的输出绑定到datagrid控件中。WPF总是冻僵。

我使用WPF,.NET 4和杯标微作为MVVM框架。

以下是问题代码:

XAML:

代码语言:javascript
复制
        <StackPanel Orientation="Vertical" Grid.Column="1">
            <DataGrid Name="Calls"/>
        </StackPanel>

ViewModel:

代码语言:javascript
复制
        public IList<Call> Calls
        {
            get { return _class; }
            set
            {
                _class = value;
                NotifyOfPropertyChange(()=>Calls);
            }
        }

        public void OpenTsv()
        {
            Task.Factory.StartNew(() =>
            {
                var dlg = new Microsoft.Win32.OpenFileDialog 
{ DefaultExt = ".tsv", Filter = "Tsv documents (.tsv)|*.tsv" };

                bool? result = dlg.ShowDialog();

                IList<Call> calls = new List<Call>();

                if (result == true)
                {
                    Path = dlg.FileName;
                    calls = TsvParser.Parse(Path);
                }

                Execute.OnUIThread((System.Action)(() =>
                { Calls = calls; }));
            });

        }

如何将属性调用从ViewModel绑定到DataGrid控件而不冻结?

EN

回答 2

Stack Overflow用户

发布于 2012-11-07 18:53:44

一个可能的答案是简单地不加载18000项。不管怎么说,在过滤到一个更容易管理的数字之前,没有人会仔细检查所有这些项目。

票数 2
EN

Stack Overflow用户

发布于 2011-11-04 20:38:48

我认为VirtualizingStackPanel.IsVirtualizing属性可以解决这个问题:

代码语言:javascript
复制
<DataGrid Name="Calls" VirtualizingStackPanel.IsVirtualizing="True" />
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6562033

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档