none
exit from a page

    Question

  • I have a page with an exit button:

    <Button Content="Exit" Height="23" HorizontalAlignment="Right" Margin="0,461,632,0" Name="button2" VerticalAlignment="Top" Width="75"   Click="button1_Click" Tag="Exit" />

    the cs code:

           private void button1_Click(object sender, RoutedEventArgs e)
            {
                Button btn = sender as Button;
                if (btn.Tag.Equals("Upload")) { }
                else if (btn.Tag.Equals("Exit"))
                {
     
                 }
            }

    What do I put in the Exit section to make the page go away, and just the current page?

    Boyd

    Thursday, April 07, 2011 3:20 PM

All replies

  • you can do smth like

    this.NavigationService.Navigate(new Uri(<some_address>));

    Thursday, April 07, 2011 3:38 PM
  • Tried that, but what I get is recursion.

    MainWorkPage navigates to SysConfig.

    SysConfig navigates to ManinWorkPage.

    Results in recursion.

     

    But what I want is for SysConfig page to exit!

    The Page comes with an exception handler from the VS studio template:

    void Current_Exit(object sender, EventArgs e)
            {
                //throw new NotImplementedException();
            }

    So how do I throw this exeption, or invoke this event, or whatever is required to cause a page exit to occur?

     

    Thursday, April 07, 2011 4:14 PM
  • MainWorkPage navigates to SysConfig.

    SysConfig navigates to ManinWorkPage.

    Results in recursion.

    So MainWorkPage should not navigate to SysConfig.

    Thursday, April 07, 2011 10:47 PM
  • My entry point to the page code:

    ===============

            public SysConfig()
            {

                InitializeComponent();
                this.DataContext = this;
                ConfBGImage = App.GlobalVariables.WelcomeBackgroundImage;
                ConfSiteImage = App.GlobalVariables.SiteImage;
                ConfVCIImage = App.GlobalVariables.VCIImage;
                Application.Current.Exit += new EventHandler(Current_Exit);  

            }

            void Current_Exit(object sender, EventArgs e)
            {
                //throw new NotImplementedException();
            }

    ==================

    The Current_Exit does NOT do as I expected - it is invoked when the application exits, not just the page.

    But before that, I still need to terminate the current page and, by default, go back to the previous page.

    Since 'this.DataContext = this;' is required to initialize the current page, I presume something similar in reverse has to be done to go back to the previous page.

    A childwindow does this with an exit button, but the childwindow is not bound to a frame.

    Help?!


     

    Friday, April 08, 2011 10:23 AM
  • Hi,

    But before that, I still need to terminate the current page and, by default, go back to the previous page.

    If you don't want to use the NavigationService then there is trick: using the Tag property of Frame to store the previous information.

    Assume there is a Frame to load the page in the MainPage and laod the MainWorkPage by default. (Both ManiWorkPage and SysConfig page in Views Folder)

    <navigation:Frame Tag="SysConfig"  x:Name="ContentFrame" Source="/Views/MainWorkPage.xaml" />

    In MainWorkPage, the Button Click envent handler like this:

            private void button1_Click(object sender, RoutedEventArgs e)
            {
                Frame frame = this.Parent as Frame;
                string uriString = "/Views/" + frame.Tag.ToString() + ".xaml";
                frame.Source = new Uri(uriString,UriKind.Relative);
                frame.Tag = "MainWorkPage";
            }

    In SysConfig, the Button Click envent handler like this:

    private void button1_Click(object sender, RoutedEventArgs e)
            {
                Frame frame = this.Parent as Frame;
                string uriString = "/Views/" + frame.Tag.ToString() + ".xaml";
                frame.Source = new Uri(uriString,UriKind.Relative);
                frame.Tag = "SysConfig";
            }

    If above is not what you need, please let me know.

    Hope this helps.

     

    Regards

    Monday, April 11, 2011 8:18 AM
  • I am starting to think I am going down the wrong road here.

    Maybe "page" is not what I really want here.

    My objective is to have a "master" display structure with tab based goups of selection options on the left side ( got that far ) with a display area to the right where different "applications" are displayed.  I am trying to use generic terms so as not to be confused with Silverlight specific object names.  These "applications" would behave much as "child windows" would in a Windows Desktop application: contained within the above described display area, be able to maximize, minimize, iconize to the bottom of the display area, exit and have multiple instances of each "child window".  Each such "child window" or "application" would be independant of each other beyond sharing the display area as do desktop windows.

    Maybe "page" is not what I want for each of these "applications"

     

    Any thoughts?

     

    Boyd

    Monday, April 11, 2011 10:28 AM