ujjaval
ujjaval

Reputation: 1533

How to change the WPF window's lable text from another wpf window

I have one Page Call Page 1 and on page one there are 1 Controls - label - Button

On click on button I am going to open new Wpf window and in that There is a button and on that button's click i want to change the 1st window label text.

LobbyStandardPopupView objLobbyStandardPopupView = new LobbyStandardPopupView();
objLobbyStandardPopupView.Show();

LobbyStandardView objLobbyStandardView = new LobbyStandardView();
objLobbyStandardView.Ring_Game.Text = "Hello";

I try to created the object and change the control value but its not effected.

Upvotes: 1

Views: 3724

Answers (1)

michele
michele

Reputation: 2091

On your calling window:

ChildWindow w = new ChildWindow ();
w.Owner = this; //here your calling window
w.Show();

On your child window:

(this.Owner as YourMainWindow).YourProperty  = "Your Text";

the Owner property is a Window, so if you want to access a your custom property you have to cast to your window type.

In your case, using a Page, add this proprerty to your LobbyStandardPopupView:

 public LobbyStandardView mycallingpage = null;
 public LobbyStandardPopupView(LobbyStandardView callingPage)
 {
     InitializeComponent();
     mycallingpage = callingPage;
 }

and in your button event:

mycallingpage.Ring_Game.Text = "Hello";

Upvotes: 6

Related Questions