Click here to Skip to main content
15,921,452 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using WPF, and have a MainWindow.xaml, also I have a user control Page_SwitcherMenu.xaml, practically this is common for other user controls.

I have a label in Page_SwitcherMenu.xaml which monitors network activity, if LAN is down label background turns red.

I need to implement the code in MainWindow.xaml.cs, the label name is lbl_LAN and is located in Page_SwitcherMenu.xaml.

How can I do this? I have tried to use binding but did not manage to.

What I have tried:

MainWindow.xaml.cs contains the following:
C#
public MainWindow()
        {
            InitializeComponent();
            this.WindowStyle = WindowStyle.None;
            this.AllowsTransparency = false;
            PageSwitcher.pageSwitcher = this;
            PageSwitcher.Switch(new Page_Info());

            NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged);
        }

 void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
        {
            GlobalData.NetworkOnline = e.IsAvailable;
            if (GlobalData.NetworkOnline == true)             
               
                lbl_LAN.Background = Brushes.PaleGreen;
            else
                lbl_LAN.Background = Brushes.Red;
        }
Posted
Updated 19-Apr-16 3:22am

1 solution

As the question turned out to be very popular, and my previous answers often were not well understood, probably were not clear enough, I decided to write a Tips/Trick article complete with detailed code samples and explanations: Many Questions Answered at Once — Collaboration between Windows Forms or WPF Windows.

—SA
 
Share this answer
 
Comments
datt265 19-Apr-16 10:05am    
Sorry for my ignorance, but still cannot understand how can I solve my problem after going through your code.
Sergey Alexandrovich Kryukov 19-Apr-16 14:06pm    
Then you probably have to explain what is unclear.
Do you have a label which other window instance should modify? Then the window having this label needs to implement some interface writing to its value (and/or reading, and anything else you need), and the interface reference should be passed to the window instance(s) which needs to work with this label. Same thing with any other controls or other UI elements.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900