简体   繁体   中英

Custom Events in User Controls

I have an application which consist of one "MainWindow" and inside main i have called a user control "loginControl" like this;

<!-- Login user Control -->
<local:LoginView x:Name="loginControl" HorizontalAlignment="Center" VerticalAlignment="Center" />

Now, inside the "loginControl" i have also three controls like this;

<local:ForgotPassword x:Name="userControlForgotPassword" Visibility="Collapsed" />
<local:CreateNewUser x:Name="userControlCreateNew" Visibility="Collapsed" />
<local:ChangePassword x:Name="userControlChangePassword" Visibility="Collapsed" />

and in code behind of "loginControl" i have called these events;

private void hyperLinkCreateNew_Click(object sender, RoutedEventArgs e)
{
    userControlCreateNew.Visibility = System.Windows.Visibility.Visible;
}

private void hyperForgotPassword_Click(object sender, RoutedEventArgs e)
{
    userControlForgotPassword.Visibility = System.Windows.Visibility.Visible;
}

private void hyperLinkChangePassword_Click(object sender, RoutedEventArgs e)
{
    userControlChangePassword.Visibility = System.Windows.Visibility.Visible;
}

Now, what i want is that, when i click on "create New" ( which is a link in 'loginControl' and change the visibility of "create new usr control"). The "loginControl" window should be disappered by using custom events. How could i do that?. Thanks in advance.

private void hyperLinkCreateNew_Click(object sender, RoutedEventArgs e)
{
    userControlCreateNew.Visibility = System.Windows.Visibility.Visible;
    Window parent = Window.GetWindow(this);
    LoginView loginView = (LoginView)(parent.FindName("loginControl"));
    loginView.Visibility = System.Windows.Visibility.Hidden;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM