Reputation: 377
I have Login User Control
, I want that when the user would click some button inside the user control I need it to make visible some textBox
.
In main window I have:
<local:LoginUserCon />
<TextBox x:Name="myTextBox" Visibility="Collapsed"/>
I tried: (In Login User Control):
void Login_Btn(object sender, RoutedEventArgs e)
{
Application.Current.MainWindow.myTextBox.Visiblity = Visibility.Visible;
}
But it says:
'Window' does not contain a definition for 'myTextBox' and no accessible extension method 'myTextBox'...
Upvotes: 1
Views: 594
Reputation: 169370
Application.Current.MainWindow
returns a Window
. You need to cast it to whatever your window type is, like for example MainWindow
:
void Login_Btn(object sender, RoutedEventArgs e)
{
MainWindow mainWindow = Application.Current.MainWindow as MainWindow;
if (mainWindow != null)
mainWindow.myTextBox.Visiblity = Visibility.Visible;
}
Upvotes: 2