列表类型更新 [英] List Type update

查看:138
本文介绍了列表类型更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上课

public class SignalRounding
    {
        public DateTime timee { get; set; }
        public string symbol { get; set; }
        public double price { get; set; }
        public double round { get; set; }
    }

创建列表

public static List<SignalRounding> SignalR;
SignalR = new List<SignalRounding>();
ListView.ItemsSource = SignalR;
ListView.Items.Refresh();

添加一些信息

SignalR.Insert(0, new SignalRounding()
                {
                    timee = DateTime.Now,
                    symbol = symbol,
                    price = price,
                    round = round
                });

再次更新

ListView.Items.Refresh();

现在显示在列表的ListView我,但我想改为显示的时间是在过去10分钟符号的行数。最后补充说,满足条件的应在列表视图中的第一个。

Now displays List in my ListView, but I want to be displayed instead of the time the number of rows that were for a symbol in the past 10 minutes. Last added that satisfies the conditions should be the first in listview.

推荐答案

我的认为的,这是你在找什么......这需要在你的SignalR对象的列表,过滤器的任何年龄超过10分钟,基团用符号,并返回的时间顺序排列的聚集体的列表,然后数量。

I think this is what you're looking for... This takes in a list of your SignalR object, filters any that are older than 10 minutes, groups by symbol, and returns the list of aggregates sorted by the time, and then the quantity.

此假设你有一个名为的ListView LV (请的的不名物体一样的类)。

This assumes you have a ListView named lv (please, please don't name objects the same as their class).

请注意:我加入 Thread.sleep代码()刚刚返回在这个例子有些不同时间戳的调用;应该显然不是在你的code,否则。

Note: I added a call to Thread.Sleep() just to return some different timestamps in this example; that should obviously not be in your code otherwise.

public partial class MainWindow : Window
    {
        public static List<SignalRounding> SignalR;

        public MainWindow()
        {
            InitializeComponent();
            SignalR = new List<SignalRounding>();

            var r = SignalR.Where(t => t.time >= DateTime.Now.AddMinutes(-10))
            .GroupBy(g => g.symbol)
            .Select(s => new
            {
                Symbol = s.Key,
                Quantity = s.Count(),
                LastUpdated = s.Max(x => x.time),
                Price = s.Single(l => l.time == s.Max(x => x.time)).price,
                Round = s.Single(l => l.time == s.Max(x => x.time)).round
            })
            .OrderByDescending(x => x.LastUpdated)
            .ThenByDescending(x => x.Quantity);

            addStuff();

            lv.ItemsSource = r;
        }

        private void addStuff()
        {
            for (int i = 0; i < 15; i++)
            {
                SignalR.Insert(0, new SignalRounding()
                {
                    time = DateTime.Now,
                    symbol = i % 10 == 0 ? "second" : i % 5 == 0 ? "third" : "first",
                    price = 0.25 * i,
                    round = i
                });
                Thread.Sleep(500);
            }
        }
    }


    public class SignalRounding
    {
        public DateTime time { get; set; }
        public string symbol { get; set; }
        public double price { get; set; }
        public double round { get; set; }
    }

这篇关于列表类型更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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