Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
XML
<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
Updated 21-Jan-13 1:29am
v2

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
C#
if( Authnticate(txtUname.Text,pbPassword.Password)
{
 Window2 objWindow2=new Window2();
objWindow2.Show();
//or objWindow2.ShowDialog();
}


Wpf windows can be opened and closed almost the similar way of windows form.
 
Share this answer
 
Comments
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.

thanks
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>


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:

C#
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.
 
Share this answer
 
v2
Comments
[no name] 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900