Esempio n. 1
0
#pragma warning disable 1998 // Async required for Windows UWP support for multiple views
        private async void RegionManager_RegionCreated(IRegionManager sender, IApplicationRegion e)
#pragma warning restore 1998
        {
#if WINDOWS_UWP

            var isPrimary = RegionManager.IsPrimaryRegion(e);
            var newView = isPrimary
                ? CoreApplication.MainView
                : CoreApplication.CreateNewView();
            var newViewId = 0;
            var context = new UniversalUIContext(newView.Dispatcher);
            e.RegisterForUIAccess(context);



            await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,  () =>
            {
                var frame = new Frame();

                var region = e;

                var hasStates = region as IHasStates;
                var sm = (region as IHasStates)?.StateManager;
                if (sm != null)
                {

                    var groups = sm.StateGroups;
                    var inotifier = typeof(INotifyStateChanged<>);
                    foreach (var stateGroup in groups)
                    {
                        var groupNotifier = inotifier.MakeGenericType(stateGroup.Key);
                        if (stateGroup.Value.GetType().GetTypeInfo().ImplementedInterfaces.Contains(groupNotifier))
                        {
                            var fnt = typeof(FrameNavigation<>).MakeGenericType(stateGroup.Key);
                            var fn = Activator.CreateInstance(fnt, frame, stateGroup.Value);
                        }
                    }
                }

#if WINDOWS_UWP
                frame.Navigated += Frame_Navigated;
#endif
                //var interfaces = region.GetType().GetInterfaces();
                //foreach (var it in interfaces)
                //{
                //    if (it.IsConstructedGenericType && 
                //    it.GetGenericTypeDefinition() == typeof(IHasViewModelStateManager<,>))
                //    {
                //        var args = it.GenericTypeArguments;
                //        var fnt = typeof (FrameNavigation<,>).MakeGenericType(args);
                //        var fn = Activator.CreateInstance(fnt, frame, region);//, string.Empty);
                //    }
                //}


                Window.Current.Content = frame;

                region.CloseRegion += Region_CloseRegion;

                if (hasStates != null)
                {
                    hasStates.StateManager.GoToPreviousStateIsBlockedChanged +=
                        StateManager_GoToPreviousStateIsBlockedChanged;
                }

                Window.Current.Activated += Current_Activated;

                Window.Current.Activate();

                newViewId = ApplicationView.GetForCurrentView().Id;

                RegionWindows[region.RegionId] = Window.Current.CoreWindow;

                if (isPrimary)
                {
                    region.Startup(sender as IRegionManager);
                }
                else { 
                Task.Run(async () => await region.Startup(sender as IRegionManager));
                }


            });

            if (!isPrimary)
            {
                var viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
                Debug.WriteLine(viewShown);
            }
#endif
        }
Esempio n. 2
0
        private void RegionManager_RegionIsClosing(IRegionManager sender, IApplicationRegion e)
        {
            var view = RegionWindows.SafeValue<string, CoreWindow, CoreWindow>(e.RegionId);
            view.Close();

        }