How to go back to the Main Window in WPF(Navigation Service) [Resolved]

Posted by Vuyiswamb under WPF on 2/2/2013 | Points: 10 | Views : 6206 | Status : [Member] [MVP] [Administrator] | Replies : 3
Good Day All

I have a Kinect Application , i am having trouble with navigation , so i dont like the creation of object of windows everytime i nagivate from one to another page. so i converted all other windows to WPF pages and created only one window wich will be the Startup screen where Navigation will begin. So Other windows might also contain Menu's so to cut the story short , i can nagivate between WPF pages and do anything i want. but i want to be able to go to the Main Page(Window) which has the Menus. Which means i am trying to navigate from a Page to a Window.

Main Window has the Frame


         <DockPanel>
<Frame x:Name="_mainFrame" />
</DockPanel>


and i cna navigate to the pages with no problems and between them , but when i want to go to the main Window from a Page i cant.

Thank you for posting at Dotnetfunda
[Administrator]



Responses

Posted by: Vuyiswamb on: 2/4/2013 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down

Resolved
That is exactly what i don't want to do. I resolved this by converting all the windows to pages. and left only one Window for Navigation. One more thing i said i am creating a Kinect applications, so i can use a hyperlink in a Kinect application, users use gestures to interact with the system.



Thank you for posting at Dotnetfunda
[Administrator]

Vuyiswamb, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shubham on: 2/4/2013 [Member] Starter | Points: 25

Up
0
Down
hi!!! you can do this
from
<Hyperlink NavigateUri="mainWindow.xaml">
Navigate to Another Page
</Hyperlink>

Here is the documentation you need :
http://msdn.microsoft.com/en-us/library/ms750478.aspx.

and in c#

Application.Current.MainWindow = newWindow;
newWindow.Show();
sourceWindow.Close();









Thanks&Regards:-
Shubham Choudhary
Software Engineer
www.facebook.com/shubham.kunar

Vuyiswamb, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj.Net on: 4/10/2013 [Member] Starter | Points: 25

Up
0
Down

hi!!!
i have used RoutedEventArgs please follow the steps.

Step1:App.xaml
<Application x:Class="CRC.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="Application_Start" >
</Application>

Step2:App.cs
public partial class App : Application
{
private void Application_Start(Object sender, System.Windows.StartupEventArgs e)
{

MainWindow mainWindow = new MainWindow();
mainWindow.ShowDialog();
}
}
}
Step3:MainWindow.Xaml
<Window x:Class="CRC.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CRC"
Title="CRC Application" Width="1280" Height="960"


MinHeight="800" MinWidth="600" HorizontalAlignment="center" mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="960"
d:DesignWidth="1280" WindowState="Maximized" WindowStyle="None" Topmost="False" MouseDown="MainWindow_MouseDown" AllowsTransparency="False" Visibility="Collapsed">

<Grid x:Name="grdMain" Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Viewbox Stretch="Fill">
<Frame x:Name="_mainFrame" NavigationUIVisibility="Hidden" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Margin="0" ClipToBounds="False"/>
</Viewbox>
</Grid>

</Window>

Step4:Wpf Page
namespace Application
{
/// <summary>
/// Interaction logic for wpfPage.xaml
/// </summary>
public partial class wpf : Page
{

public static readonly RoutedEvent TimeOutEvent = EventManager.RegisterRoutedEvent("TimeOut", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(WpfPage));
//******************************************
public AddressPage()
{
InitializeComponent();

}
public event RoutedEventHandler TimeOut
{
add { AddHandler(TimeOutEvent, value); }
remove { RemoveHandler(TimeOutEvent, value); }
}

void RaiseTimeOutEvent()
{
RoutedEventArgs newEventArgs = new RoutedEventArgs(WpfPage.TimeOutEvent);
RaiseEvent(newEventArgs);
}
private void btnEnter_Click(object sender, RoutedEventArgs e)
{
RaiseTimeOutEvent();
}
}
Step5:Mainwindow.cs
public partial class MainWindow : Window
{
public MainWindow()
{
InitializePage();
}
private void InitializePage()
{
WpfPage wpfpage=new WpfPage();
this.AddHandler(WpfPage.TimeOutEvent, new RoutedEventHandler(HandleWpfPageTimeOut));
}
private void HandlePageTimeOut(object sender, RoutedEventArgs args)
{
_mainframe.navigate(wpfpage);
}
}

BY
Rajesh
MY Mail Id:rajesh4132@gmail.com
India

If it helps/directs you towards the solution,Mark This Response as Answer link
--
Rajesh

Vuyiswamb, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response