WinUI3: How to capture wifi change event in WinUI3 desktop app

Anonymous
2023-01-05T18:01:24.223+00:00

Hi,

I'm working on the WinUI3 desktop application. How can we receive an event when the network to which the system is connected to is changed?

I tried searching online, but I was not able to find any solutions to receive this event in WinUI3. It would be of great help if you could help me achieve this.

Thank you.

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
430 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
2,617 questions
No comments
{count} votes

Accepted answer
  1. Junjie Zhu - MSFT 5,956 Reputation points Microsoft Employee
    2023-01-06T02:51:26.59+00:00

    Hello @Anonymous ,
    Welcome to Microsoft Q&A!

    You can use Event NetworkInformation.NetworkStatusChanged.

        public MainWindow()  
        {  
            this.InitializeComponent();  
            NetworkInformation.NetworkStatusChanged += NetworkStatusChanged;  
        }  
    
        private void NetworkStatusChanged(object sender)  
        {  
            Debug.WriteLine("NetworkStatusChanged");  
        }  
    

    I remember that your project is Winui3 C++, the following information is for your reference.
    1.INetworkEvents::NetworkConnectivityChanged
    The NetworkConnectivityChanged method is called when network connectivity related changes occur.
    2.Receiving Event Notifications Through WMI

    Thank you.
    Junjie


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful