So basically my listview keeps appending messages which are inserted. I use the following code which always makes the listview scroll to the bottom. Please note, i have many threads in my application so i need to update the UI using the following way
this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
{
this.listviewMessages.ScrollIntoView(this.listviewMessages.Items[listviewMessages.Items.Count - 1]);
}));
Now, i have a eventhandler which raises a event whenever internet connection is lost
NetworkStatus.AvailabilityChanged += new NetworkStatusChangedHandler(this.NetworkChange_NetworkAvailabilityChanged);
When this event is called my scroll of the listview goes to the top despite calling
this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
{
this.listviewMessages.ScrollIntoView(this.listviewMessages.Items[listviewMessages.Items.Count - 1]);
}));
This is the code which is called to check if internet connectivity is present or not
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;
}
}
}
}
}
The items count of the listview is also correct. Could someone please help me on this. What am i doing wrong?