Search code examples
c#wpfwifiwindows-8.1togglebutton

C# WPF Windows 8 WIFI status of toggle button


How to get WIFI toggle button status by C# WPF in Win8?

The toggle button is as follow...

enter image description here


Solution

  • You can check radio state of Wi-Fi by Native Wifi API. Using some codes of Managed Wifi API project, I wrote a sample.

    using System.Diagnostics;
    using NativeWifi;
    
    public static class WlanRadio
    {
        public static void CheckInterfaceStates()
        {
            using (var client = new WlanClient())
            {
                foreach (var @interface in client.Interfaces)
                {
                    Trace.WriteLine($"[{@interface.InterfaceName}]");
    
                    foreach (var state in @interface.RadioState.PhyRadioState)
                    {
                        Trace.WriteLine($"PhyIndex: {state.dwPhyIndex}");
                        Trace.WriteLine($"SoftwareRadioState: {state.dot11SoftwareRadioState}");
                        Trace.WriteLine($"HardwareRadioState: {state.dot11HardwareRadioState}");
                    }
                }
            }
        }
    }
    

    When both software radio state and hardware radio state (it represents the state of hardware radio switch) are ON, Wi-Fi is ON. Otherwise, Wi-Fi is OFF.