public ObservableCollection <Library.NetworkAdapter> AddAdaptersToCollection(bool showConnectedOnly = false)
        {
            NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();

            if (showConnectedOnly)
            {
                foreach (NetworkInterface nic in nics)
                {
                    var adapter = new Library.NetworkAdapter(nic);
                    if (adapter.Status == "Up" && adapter.Type != "Loopback" && !adapter.Description.Contains("Bluetooth Device") && !adapter.Description.Contains("Virtual Adapter"))
                    {
                        adapterCollection.Add(adapter);
                    }
                }
                return(adapterCollection);
            }

            foreach (NetworkInterface nic in nics)
            {
                var adapter = new Library.NetworkAdapter(nic);
                if (adapter.Type != "Loopback" && !adapter.Description.Contains("Bluetooth Device") && !adapter.Description.Contains("Virtual Adapter"))
                {
                    adapterCollection.Add(adapter);
                }
            }
            return(adapterCollection);
        }
        /// <summary>
        /// Finds the adapter that's been selected from the ListView
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public Library.NetworkAdapter FindSelectedAdapter(SelectionChangedEventArgs e)
        {
            //if (e.AddedItems.Count < 1)
            //TODO: Please select an adapter

            string adapterName = e.AddedItems[0]?.ToString();

            Library.NetworkAdapter selectedAdapter = adapterCollection.Where(x => x.Name == adapterName).FirstOrDefault();
            return(selectedAdapter);
        }
        private void LvAdapters_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                Library.NetworkAdapter selectedAdapter = FindSelectedAdapter(e);

                rtbExraDetails.Clear();     // Clear existing info from TextBox

                // Print Extra Details to TextBox
                rtbExraDetails.AppendText($"Index\t\t{selectedAdapter.Index}\r\nDescription:\t{selectedAdapter.Description}\r\nType:\t\t{selectedAdapter.Type}\r\nStatus:\t\t{selectedAdapter.Status}\r\nDHCP Server:\t{selectedAdapter.DhcpServerAddress}\r\nMAC Address:\t{selectedAdapter.MacAddress}\r\nGUID:\t\t{selectedAdapter.Guid}");

                // Print properties to relevant TextBoxes
                tbIpAddress.Text      = selectedAdapter.IpAddress;
                tbSubnetMask.Text     = selectedAdapter.SubnetMask;
                tbDefaultGateway.Text = selectedAdapter.DefaultGateway;
                tbPrimaryDns.Text     = selectedAdapter.PrimaryDns;
                tbSecondaryDns.Text   = selectedAdapter.SecondaryDns;

                // Select relevant RadioButton
                if (selectedAdapter.DhcpStatus)
                {
                    rUseDhcp.IsChecked = true;
                }
                else
                {
                    rStaticIp.IsChecked = true;
                }

                // Tick/Untick Automatic DNS
                if (selectedAdapter.DnsStatus)
                {
                    cbAutomaticDns.IsChecked = true;
                }
                else
                {
                    cbAutomaticDns.IsChecked = false;
                }

                AdapterIsSelected  = true;
                this.SelectedIndex = Convert.ToUInt32(selectedAdapter.Index);
                this.SelectedGuid  = selectedAdapter.Guid;
            }
        }