WPF项目有两页 [英] WPF Project with two pages

查看:111
本文介绍了WPF项目有两页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的WPF应用程序中,



我有 MainWindow.xaml

和2页如 LoginPage.xaml Export.xaml



我使用下面的代码在mainwindow中调用了这两个页面。

In my WPF applcation,

I have MainWindow.xaml
and 2 pages like LoginPage.xaml and Export.xaml

I called these two pages in mainwindow using below code.

<Frame Source="LoginPage.xaml" NavigationUIVisibility="Hidden" />
<Frame Source="Export.xaml" NavigationUIVisibility="Hidden" Visibility="Hidden" />

<我的登录页面中有
我们有一个登录界面,当用户点击登录按钮时,将打开导出页面。



我怀疑是这种正确的做法。


in my loginpage we have a login screen, when user hits the login button Export page will open.

I am having a doubt like is this correct way of doing.

推荐答案

我不确定我是否理解你的问题,但如果你想在Windows之间导航那么不是基于事件的?我的意思是首次登录应该出现。用户填写凭证并单击登录后,身份验证方法应该有效。验证后会出现新表格吗?



如果这是您的工作流程,为什么不使用代码而不是xml?



喜欢登录按钮事件处理程序

I am not sure if I have understood your question well, but if you want to navigate between windows will that not be event based? I mean first login should appear. After user fills the credential and click ''Login'', authentication method should work. After authentication new form should appear?

If this is your workflow, why not use code instead of xml?

Like from Login buton event handler
if( Authnticate(txtUname.Text,pbPassword.Password)
{
 Window2 objWindow2=new Window2();
objWindow2.Show();
//or objWindow2.ShowDialog();
}





Wpf窗口可以打开和关闭几乎与Windows窗体类似的方式。



Wpf windows can be opened and closed almost the similar way of windows form.


在主窗口中我只使用了一个框架:

In the Main window I used only one frame:
<window x:class="WpfApplication1CP.MainWindow" xmlns:x="#unknown">
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <grid>
        <frame source="LoginPage.xaml" navigationuivisibility="Hidden" />
     
    </grid>
</window>





我添加了两个简单页面:LoginPage.xaml和Export.xaml



这是Loginpage.xaml





I added two simple pages: LoginPage.xaml and Export.xaml

Here is Loginpage.xaml

<page x:class="WpfApplication1CP.LoginPage" xmlns:x="#unknown">
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" 
      d:DesignHeight="300" d:DesignWidth="300"
	Title="LoginPage">;

    <grid>
        <label content="Login" horizontalalignment="Left" margin="130,155,0,0" verticalalignment="Top/><br mode=" hold=" />        <Button Content=" button=" HorizontalAlignment=" left=" Margin=" top=" Width=" 75=" Click=" button_click_1="/>
</grid>





现在点击按钮事件:





Now in the button click event:

private void Button_Click_1(object sender, RoutedEventArgs e)
        {

            var wnd = Window.GetWindow(this);
            Grid g = (Grid)wnd.Content;
            Frame f=(Frame)g.Children[0];

            f.Source = new Uri("Export.xaml", UriKind.RelativeOrAbsolute);
        }





我们获取登录页面的父窗口,即MainWindow。我们获得了适当的子节点,它是帧的占位符(即Frame)。更新帧源。



希望这有帮助。



We obtain the parent window of Login page which is MainWindow. We obtain the appropriate child which is the placeholder of the frames ( i.e Frame). Update the Frame source.

Hope this helps.


这篇关于WPF项目有两页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆