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

Harshithraj1871 1,686 Reputation points
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 development | Windows App SDK
Developer technologies | C++
0 comments No comments
{count} votes

Accepted answer
  1. Junjie Zhu - MSFT 21,646 Reputation points
    2023-01-06T02:51:26.59+00:00

    Hello @Harshithraj1871 ,
    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.