Popup Container

Sep 15, 2010 at 10:46 AM

Hi Orktane,

We have a requirement which needs to work as follows. We have a list of contacts. The list has a context menu which must contain the following actions, add, edit and delete. When the add or edit buttons are clicked we need to navigate to the add/edit contact view, but it must be shown in a modal window.

Is it possible to implement a navigation container which exists inside a modal window? How would you go about implementing this?

Thanks

Sep 15, 2010 at 12:49 PM

Aaarggg, sorry about te duplicate post, I just saw the prev question now.

 

FYI, I did the following to solve the issue. Please let me know what you think.

Thanks

using System.Windows;
using System.Windows.Controls;
using nRoute.Components.Routing;
using nRoute.Controls;
using nRoute.Navigation;
using nRoute.Navigation.Containers;

namespace AgathaWithNroute
{
    public class ModalContainer : NavigationContainer
    {
        protected override void OnProcessResponse(NavigationResponse response)
        {
            // we won't handle it the response, if it is not the active request!
            if (!response.Request.Equals(base.ActiveNavigationRequest)) return;

            // we check if the navigation was successfull or not
            if (response.Status != ResponseStatus.Success)
            {
                // we raise navigation failed and return - note for cancelled it returns to navigated state 
                var failedEventArgs = new NavigationFailedEventArgs(this, response.Request, response.Status, response.Error);
                OnNavigatingFailed(failedEventArgs);
                return;
            }

            // we save our supporters and use them - note_ we need to save this to access later
            CurrentNavigationLifecycleSupporter = response.NavigationLifecycleSupporter;
            CurrentNavigationStateSupporter = response.NavigationStateSupporter;

            // if the content support navigation, we pass in the request/response merged parameters
            if (this.CurrentNavigationLifecycleSupporter != null)
            {
                CurrentNavigationLifecycleSupporter.Initialize(response.ResponseParameters);
                Title = CurrentNavigationLifecycleSupporter.Title ??
                    Navigation.GetTitle(response.Content as DependencyObject);
            }
            else
            {
                Title = Navigation.GetTitle(response.Content as DependencyObject);
            }

            // we save the url and the content
            CurrentNavigationRequest = response.Request;

            var window = new ChildWindow {Content = response.Content};
            window.Show();

            // we raise completed
            OnNavigationCompleted(new NavigatedEventArgs(this, response.Request));
        }
    }
}

 

 

Coordinator
Sep 16, 2010 at 9:42 AM

Nicely done, but I wanna draw a distinction between the normal/expected use of containers and the way you've done this. Now, normally when you navigate within a container, one of the idea/assumption is that you can by not defining a specific container walk up the visual tree and get hold of the owning container so you can navigate within the same container. This is same behavior like when using an IFrame within an Html page. Now, in your implementation when trying to navigate from within the child window if I walk up the visual tree I either won't find the container or might select a parent/application-wide container. Now this is not wrong or anything, but something you need to be aware - or more specifically, you need to be aware of where the navigation will take place, if at all. You can control where the navigation takes hold, by specifying the handler or hander name. 

Also, FYI one of the ways I've used child-windows is to place a container within it - and then I proxy calls into it, this way navigating within the container works like normal. I suppose, if you require, you can do the reverse here - which is to have the child window implement INavigationHandler and proxy it's calls to the ModalContainer. 

Hope this makes sense,
Rishi