Click here to Skip to main content
13,593,447 members
Rate this:
Please Sign up or sign in to vote.
See more:
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.
Posted 21-Jan-13 0:25am
Updated 21-Jan-13 1:29am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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();
//or objWindow2.ShowDialog();

Wpf windows can be opened and closed almost the similar way of windows form.
D-Kishore 21-Jan-13 22:27pm
Yes i understood what you are saying,

At the start we planed to design all the controls in same window,like different panels.

I mean login in one panel and export in another panel.

once the mainwindow loaded we are displaying only login panel, once the authentication done we disabling the login panel and displaying export panel.

if we follow this at the designing time we are facing problems like send to back and bring front of the panels arrangements.

For this reason we planned to implement different pages in same window.Because of that i posted this question in code project.

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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

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

Here is Loginpage.xaml

<page x:class="WpfApplication1CP.LoginPage" xmlns:x="#unknown">
      d:DesignHeight="300" d:DesignWidth="300"

        <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="/>

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);

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.
Member 10786704 30-Apr-14 16:51pm
Now in the button click event:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web03-2016 | 2.8.180618.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100