Beispiel #1
0
        private void WireView(FrameworkElement view, Object viewModel, IDictionary <String, String> navigationParameters)
        {
            INavigationAware navigationAware = viewModel as INavigationAware;

            if (navigationAware != null)
            {
                RoutedEventHandler handler = null;
                handler = (o, e) =>
                {
                    navigationAware.Navigated(navigationParameters);
                    view.Loaded -= handler;
                };

                view.Loaded += handler;
            }
            view.DataContext = viewModel;
        }
Beispiel #2
0
        /// <summary>
        /// Loads the content from specified uri.
        /// </summary>
        /// <param name="uri">The content uri</param>
        /// <returns>
        /// The loaded content.
        /// </returns>
        protected override Object LoadContent(Uri uri)
        {
            FrameworkElement view = null;

            var viewInfo = this.viewLocater.LocateViewInfo(uri);

            if (viewInfo != null)
            {
                var viewType             = viewInfo.Item1;
                var viewModelType        = viewInfo.Item2;
                var navigationParameters = viewInfo.Item3;

                view = (FrameworkElement)this.resolver.Get(viewType); // get the view.

                if (viewModelType != null)
                {
                    Object viewModel = this.resolver.Get(viewModelType);

                    INavigationAware navigationAware = viewModel as INavigationAware;

                    if (navigationAware != null)
                    {
                        RoutedEventHandler handler = null;
                        handler = (o, e) =>
                        {
                            navigationAware.Navigated(navigationParameters);
                            view.Loaded -= handler;
                        };

                        view.Loaded += handler;
                    }
                    view.DataContext = viewModel;
                }
            }
            return(view);
        }