WPF页面跳转

来源:互联网 发布:淘宝客二合一链接 编辑:程序博客网 时间:2024/05/16 01:33

WPF页面跳转 以下方式:

 ①、 像做Winform程序那样,由登录窗体跳转到主窗体,  在登录窗体的 btnLoad.Click(Object sener , EventArgse){ frmMain main =new frmMain(); main.Show(); this.Close(); }

  直接Show()出来。

  有些时候,也这么写:

        private void ButtonClick(object sender, RoutedEventArgs e)        {            // Get the current button.            Button cmd = (Button)e.OriginalSource;                            // Create an instance of the window named            // by the current button.            Type type = this.GetType();            Assembly assembly = type.Assembly;                                   Window win = (Window)assembly.CreateInstance(                type.Namespace + "." + cmd.Content);             // Show the window.            win.ShowDialog();        }
上面这种写法,主要是用来将要打开多个窗体的Button按钮的Click事件,合并。
拓展 ,上述写法又涉及到了Type的使用, 反射的知识。

②、Page页面跳转

 <TextBlock HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Row="4" FontSize="10" Margin="5"> <Hyperlink NavigateUri="Regin.xaml" >注册账户</Hyperlink> </TextBlock>
    后台写法:

NavigationWindow window =new NavigationWindow();

window.Source =newUri("Page1.xaml", UriKind.Relative);

window.Show();

0 0
原创粉丝点击