引发事件时,wpf中的ListView会滚动到顶部

时间:2017-01-06 08:30:22

标签: c# wpf listview

所以基本上我的listview会继续附加插入的消息。我使用以下代码总是使listview滚动到底部。请注意,我的应用程序中有很多线程,所以我需要使用以下方式更新UI

NetworkStatus.AvailabilityChanged += new NetworkStatusChangedHandler(this.NetworkChange_NetworkAvailabilityChanged);

现在,我有一个事件处理程序,可以在互联网连接丢失时引发事件

this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
            {
                this.listviewMessages.ScrollIntoView(this.listviewMessages.Items[listviewMessages.Items.Count - 1]);
            }));

当调用此事件时,尽管调用

,列表视图的滚动仍会显示在顶部
if (NetworkInterface.GetIsNetworkAvailable())
            {
                // however, this will include all adapters
                NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
                foreach (NetworkInterface face in interfaces)
                {
                    // filter so we see only Internet adapters
                    if (face.OperationalStatus == OperationalStatus.Up)
                    {
                        if ((face.NetworkInterfaceType != NetworkInterfaceType.Tunnel) &&
                            (face.NetworkInterfaceType != NetworkInterfaceType.Loopback))
                        {
                            IPv4InterfaceStatistics statistics = face.GetIPv4Statistics();

                            // all testing seems to prove that once an interface comes online
                            // it has already accrued statistics for both received and sent...

                            if ((statistics.BytesReceived > 0) &&
                                (statistics.BytesSent > 0))
                            {
                                return true;
                            }
                        }
                    }
                }
            }

这是调用以检查互联网连接是否存在的代码

- name: Install Program
  command: /home/user/folder/program.run -- /S /D=/home/user/folder/destination/

列表视图的项目计数也是正确的。有人可以帮我这个。我做错了什么?

0 个答案:

没有答案