private void cargarPaginaInicio()
        {
            string pagina = string.Empty;

            if (this.esNueva() == true)
                pagina = BIENVENIDA;
            else
                pagina = MAINPAGE;
            
            var mapper = new UriMapper();
            mapper.UriMappings.Add(new UriMapping
            {
                Uri = new Uri(INICIO, UriKind.Relative), 
                MappedUri = new Uri(pagina, UriKind.Relative)
            });

            this.RootFrame.UriMapper = mapper;                        
        }
Exemple #2
0
        internal void addDemo(string title, string uri)
        {
            var mapper = (UriMapper)MainFrame.Resources["uriMapper"];
            if (mapper == null)
            {
                mapper = new UriMapper();
                MainFrame.Resources.Add("uriMapper", mapper);
            }
            var mapping = new UriMapping
                              {
                                  Uri = new Uri(title, UriKind.Relative),
                                  MappedUri = new Uri(uri, UriKind.Relative)
                              };
            mapper.UriMappings.Add(mapping);

            demos.Add(title, uri);
            demoList.Items.Add(title);
        }
Exemple #3
0
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Standard XAML initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            // Language display initialization
            InitializeLanguage();

            // Show graphics profiling information while debugging.
            if (Debugger.IsAttached)
            {
                // Display the current frame rate counters.
                Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are handed off to GPU with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;

                // Prevent the screen from turning off while under the debugger by disabling
                // the application's idle detection.
                // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
                // and consume battery power when the user is not using the phone.
                PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
            }

            var bingMapping = new UriMapping
                                  {
                                      Uri = new Uri("/SearchExtras", UriKind.Relative),
                                      MappedUri = new Uri("/MainPage.xaml", UriKind.Relative)
                                  };

            var mapper = new UriMapper();
            mapper.UriMappings.Add(bingMapping);
            RootFrame.UriMapper = mapper;
        }
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Standard Silverlight initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            // Setting the URI Mapper must be after the RootFrame is constructed, which occurs in InitializePhoneApplication.
            var mapper = new UriMapper();
            mapper.UriMappings.Add(new UriMapping
            {
                Uri = new Uri("/SearchExtras", UriKind.Relative),
                MappedUri = new Uri("/MainPage.xaml", UriKind.Relative)
            });
            RootFrame.UriMapper = mapper;

            // Show graphics profiling information while debugging.
            if (System.Diagnostics.Debugger.IsAttached)
            {
                // Display the current frame rate counters.
                Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are handed off to GPU with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;

                // Disable the application idle detection by setting the UserIdleDetectionMode property of the
                // application's PhoneApplicationService object to Disabled.
                // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
                // and consume battery power when the user is not using the phone.
                PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
            }
        }
 private void ReadConfiguration(XDocument doc)
 {
     if (doc.Element("navigationdata").Attribute("enablenavigationmanager").Value == "false")
     {
         navigationManagerInstance = null;
     }
     else
     {
         if (doc.Descendants("frame").Count<XElement>() == 0)
         {
             throw new MissingFieldException("No frames have been defined in NavigationMappings.xml.");
         }
         foreach (XElement element in doc.Descendants("frame"))
         {
             string key = element.Attribute("key").Value;
             string text1 = element.Attribute("type").Value;
             if (base.FindName(key) == null)
             {
                 throw new ArgumentException("The defined frame " + key + " wasn't found, navigation couldn't initialize.");
             }
             navigationManagerInstance.Frames.Add(key, (Frame) base.FindName(key));
         }
         foreach (XElement element2 in doc.Descendants("navigationmapping"))
         {
             if (element2.Attribute("key") == null)
             {
                 throw new ArgumentException("Navigationmapping is missing 'key' attribute");
             }
             string str2 = element2.Attribute("key").Value;
             foreach (XElement element3 in element2.Descendants("viewmapping"))
             {
                 try
                 {
                     INavigationMapping mapping;
                     if (element3.Attribute("viewmodel") == null)
                     {
                         throw new ArgumentException("Viewmapping is missing 'viewmodel' attribute");
                     }
                     if (element3.Attribute("view") == null)
                     {
                         throw new ArgumentException("Viewmapping is missing 'view' attribute");
                     }
                     if (element3.Attribute("frame") == null)
                     {
                         throw new ArgumentException("Viewmapping is missing 'frame' attribute");
                     }
                     string typeName = element3.Attribute("viewmodel").Value;
                     string str4 = element3.Attribute("view").Value;
                     string str5 = (element3.Attribute("state") == null) ? "" : element3.Attribute("state").Value;
                     string sframe = element3.Attribute("frame").Value;
                     Type type = Type.GetType(typeName);
                     Type type3 = typeof(NavigationMapping<>).MakeGenericType(new Type[] { type });
                     Frame frame = Enumerable.FirstOrDefault<KeyValuePair<string, Frame>>(navigationManagerInstance.Frames, (Func<KeyValuePair<string, Frame>, bool>) (f => (f.Key == sframe))).Value;
                     if (str5 == string.Empty)
                     {
                         mapping = (INavigationMapping) Activator.CreateInstance(type3, new object[] { str2, str4, frame });
                     }
                     else
                     {
                         mapping = (INavigationMapping) Activator.CreateInstance(type3, new object[] { str2, str4, frame, str5 });
                     }
                     navigationManagerInstance.NavigationMappings.Add(mapping);
                 }
                 catch (Exception exception)
                 {
                     throw new ArgumentException("An error occurred while creating the navigation mapping " + str2 + ". Please recheck the mapping.", exception);
                 }
             }
         }
         UriMapper mapper = new UriMapper();
         foreach (XElement element4 in doc.Descendants("urimapping"))
         {
             string str6 = element4.Attribute("uri").Value;
             string str7 = element4.Attribute("navigationmappingkey").Value;
             string str8 = (element4.Attribute("pagetitle") == null) ? "Page title" : element4.Attribute("pagetitle").Value;
             string str9 = (element4.Attribute("parameters") == null) ? "" : element4.Attribute("parameters").Value;
             string uriString = str6;
             string str11 = "/Bromo.Silverlight;component/MVVM/Navigation/NavigationHelper.xaml?key=" + str7;
             if (str9 != string.Empty)
             {
                 str11 = str11 + "&" + str9;
             }
             str11 = str11 + "&pagetitle=" + str8;
             Uri uri = new Uri(uriString, UriKind.Relative);
             Uri uri2 = new Uri(str11, UriKind.Relative);
             UriMapping item = new UriMapping {
                 MappedUri = uri2,
                 Uri = uri
             };
             mapper.UriMappings.Add(item);
         }
         navigationManagerInstance.UriMapper = mapper;
     }
 }
Exemple #6
0
 private void SetUriMapping()
 {
     if (RootFrame != null)
     {
         UriMapper mapper = new UriMapper();
         UriMapping mapping = new UriMapping();
         mapping.Uri = new Uri("/MainPage/{lat}/{lon}/{address}", UriKind.Relative);
         mapping.MappedUri = new Uri("/MainPage.xaml?lat={lat}&lon={lon}&address={address}", UriKind.Relative);
         mapper.UriMappings.Add(mapping);
         RootFrame.UriMapper = mapper;
     }
 }
Exemple #7
0
        // Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            //IsolatedStorageSettings.ApplicationSettings.Remove("access_token");
            //IsolatedStorageSettings.ApplicationSettings.Remove("user_id");
            db = new VkDataContext("isostore:/DataContext.sdf");
            if (!db.DatabaseExists())
                db.CreateDatabase();
            if (IsolatedStorageSettings.ApplicationSettings.Contains("access_token"))
            {
                VkApi.Authorization.AccessToken = (string)IsolatedStorageSettings.ApplicationSettings["access_token"];
                VkApi.Authorization.UserId = (string)IsolatedStorageSettings.ApplicationSettings["user_id"];
                //VkApi.Authorization.Secret = (string)IsolatedStorageSettings.ApplicationSettings["secret"];
                var mapper = new UriMapper();
                mapper.UriMappings.Add(new UriMapping() { Uri = new Uri("/LoginPage.xaml", UriKind.Relative), MappedUri = new Uri("/MainPage.xaml", UriKind.Relative) });
                this.RootFrame.UriMapper = mapper;

                new Notifications().SetupNotificationChannel();
            }
        }
Exemple #8
0
        // Do not add any additional code to this method
        private void InitializePhoneApplication()
        {
            if (phoneApplicationInitialized)
                return;

            // Create the frame but don't set it as RootVisual yet; this allows the splash
            // screen to remain active until the application is ready to render.
            RootFrame = new PhoneApplicationFrame();

            UriMapper mapper = new UriMapper();
            mapper.UriMappings.Add(new UriMapping
            {
                Uri = new Uri("/Nearby.xaml", UriKind.Relative),
                MappedUri = new Uri("/Views/Project/ProjectsListView.xaml?nearby=true", UriKind.Relative)
            });
            RootFrame.UriMapper = mapper; 
                                                    

            RootFrame.Navigated += CompleteInitializePhoneApplication;

            // Handle navigation failures
            RootFrame.NavigationFailed += RootFrame_NavigationFailed;

            // Ensure we don't initialize again
            phoneApplicationInitialized = true;
        }
Exemple #9
0
 /// <summary>
 /// Setups the URI mapper.
 /// </summary>
 private void SetupUriMapper()
 {
     UriMapper mapper = new UriMapper();
     mapper.UriMappings.Add(new UriMapping());
     mapper.UriMappings[0].Uri = new Uri("/StartPage.xaml", UriKind.Relative);
     //// mapper.UriMappings[0].MappedUri = new Uri("/Views/ViewPicturePage.xaml", UriKind.Relative);
     mapper.UriMappings[0].MappedUri = new Uri("/Views/Main.xaml", UriKind.Relative);
     //// mapper.UriMappings[0].MappedUri = new Uri("/Views/ViewPackagePage.xaml", UriKind.Relative);
     this.RootFrame.UriMapper = mapper;
 }
        public void NavigateToFragmentWithMapping()
        {
            bool complete = false;
            int eventCount = 0;

            string fragment = "frag1";
            Uri testUri = new Uri("/Page1/" + fragment, UriKind.Relative);

            UriMapping mapping = new UriMapping()
            {
                Uri = new Uri("/{pageName}/{fragment}", UriKind.Relative),
                MappedUri = new Uri(TestPagesPath + "{pageName}.xaml#{fragment}", UriKind.Relative)
            };

            UriMapper mapper = new UriMapper();
            mapper.UriMappings.Add(mapping);

            this.Frame.UriMapper = mapper;

            this.Frame.JournalOwnership = JournalOwnership.OwnsJournal;
            // Add to test surface
            this.TestPanel.Children.Add(this.Frame);

            // Wire up event handlers
            this.Frame.NavigationFailed += (sender, args) => Assert.Fail();
            this.Frame.Navigating +=
                (sender, args) =>
                {
                    // Verify this was the first event raised.
                    Assert.AreEqual<int>(1, ++eventCount);

                    Assert.IsNull(this.Frame.Source);
                    Assert.IsNull(this.Frame.CurrentSource);
                    Assert.AreEqual(testUri, args.Uri);
                    Assert.AreEqual(NavigationMode.New, args.NavigationMode);
                };
            this.Frame.Navigated +=
                 (sender, args) =>
                 {
                     // Verify this was the second event raised.
                     Assert.AreEqual<int>(2, ++eventCount);

                     Assert.AreEqual(testUri, this.Frame.Source);
                     Assert.AreEqual(testUri, this.Frame.CurrentSource);
                     Assert.AreEqual(testUri, args.Uri);
                 };
            this.Frame.FragmentNavigation +=
                (sender, args) =>
                {
                    // Verify this was the third event raised.
                    Assert.AreEqual<int>(3, ++eventCount);

                    Assert.AreEqual(testUri, this.Frame.Source);
                    Assert.AreEqual(testUri, this.Frame.CurrentSource);
                    Assert.AreEqual(fragment, args.Fragment);

                    // Test complete
                    complete = true;
                };

            this.EnqueueCallback(() => this.Frame.Navigate(testUri));
            this.EnqueueConditional(() => complete && (this.Frame.Content as Page1).VirtualsCalled.Count == 2);

            // Verify that the page virtuals fired in the correct order
            this.EnqueueCallback(() =>
            {
                var content = this.Frame.Content as Page1;
                Assert.AreEqual<string>("OnNavigatedTo", content.VirtualsCalled[0]);
                Assert.AreEqual<string>("OnFragmentNavigation", content.VirtualsCalled[1]);
            });

            this.EnqueueTestComplete();
        }
        public void ShouldNotNavigateToEmptyUriOnLoadWhenUriMapperThatDoesNotMapEmptyUri()
        {
            // Make sure the Frame isn't loaded by using a new Frame (not the one set up in the unit tests normally
            this.Cleanup();
            this.Frame = new Frame();
            this.Frame.Navigated += (sender, args) => Assert.Fail("Frame should never navigate during this test");

            bool loaded = false;
            UriMapper mapper = new UriMapper();
            UriMapping nonEmptyMapping = new UriMapping();
            nonEmptyMapping.Uri = new Uri("abc", UriKind.Relative);
            nonEmptyMapping.MappedUri = new Uri(TestPagesPath + "Page1.xaml", UriKind.Relative);
            mapper.UriMappings.Add(nonEmptyMapping);

            this.Frame.UriMapper = mapper;

            this.Frame.Loaded +=
                (sender, args) =>
                {
                    loaded = true;
                };

            this.TestPanel.Children.Add(this.Frame);

            this.EnqueueConditional(() => loaded);

            // Briefly pause in case Frame would try to Navigate
            this.EnqueueDelay(500);

            this.EnqueueTestComplete();
        }
        public void NoSourceWithEmptyUriMappingLoadsDefaultContent()
        {
            // Make sure the Frame isn't loaded by using a new Frame (not the one set up in the unit tests normally
            this.Cleanup();
            this.Frame = new Frame();

            bool complete = false;
            UriMapper mapper = new UriMapper();
            UriMapping emptyMapping = new UriMapping();
            emptyMapping.MappedUri = new Uri(TestPagesPath + "Page1.xaml", UriKind.Relative);
            mapper.UriMappings.Add(emptyMapping);

            this.Frame.UriMapper = mapper;

            this.Frame.Navigated +=
                (sender, args) =>
                {
                    Assert.AreEqual(String.Empty, args.Uri.OriginalString);

                    Assert.IsInstanceOfType(args.Content, typeof(Page1));
                    Assert.IsInstanceOfType(this.Frame.Content, typeof(Page1));

                    Assert.AreEqual(String.Empty, this.Frame.Source.OriginalString);
                    Assert.AreEqual(String.Empty, this.Frame.CurrentSource.OriginalString);

                    complete = true;
                };

            this.TestPanel.Children.Add(this.Frame);

            this.EnqueueConditional(() => complete);

            this.EnqueueTestComplete();
        }
        public void NavigatingToPageByUnmappedAndMappedUri()
        {
            int complete = 0;
            string page1String = TestPagesPath + "Page1.xaml";
            Uri page1Uri = new Uri(page1String, UriKind.Relative);
            string abcString = "abc";
            Uri abcUri = new Uri(abcString, UriKind.Relative);
            this.Frame.JournalOwnership = JournalOwnership.OwnsJournal;
            // Add to test surface
            this.TestPanel.Children.Add(this.Frame);

            Page1 firstInstance = null;

            UriMapping mapping = new UriMapping();
            mapping.Uri = abcUri;
            mapping.MappedUri = page1Uri;

            UriMapper mapper = new UriMapper();
            mapper.UriMappings.Add(mapping);
            Frame.UriMapper = mapper;

            // Wire up events
            Frame.NavigationFailed += (sender, args) => Assert.Fail(args.Exception.Message);
            Frame.Navigated +=
                (sender, args) =>
                {
                    // Verify contents of event args
                    Assert.IsTrue(args.Content is Page1);

                    // Verify contents in navigator content presenter
                    Assert.IsTrue(Frame.Content is Page1);

                    // Verify navigation context
                    Page1 frameContent = Frame.Content as Page1;
                    Assert.IsNotNull(frameContent.NavigationContext);
                    Assert.IsNotNull(frameContent.NavigationContext.QueryString);

                    Assert.AreEqual<int>(0, frameContent.NavigationContext.QueryString.Count);

                    Assert.ReferenceEquals(frameContent.NavigationService, this.Frame.NavigationService);

                    Assert.AreEqual<int>(complete, this.Frame.NavigationService.Journal.BackStack.Count);
                    Assert.AreEqual<int>(0, this.Frame.NavigationService.Journal.ForwardStack.Count);


                    if (complete == 0)
                    {
                        firstInstance = Frame.Content as Page1;

                        // Verify Uri
                        Assert.AreEqual<Uri>(page1Uri, args.Uri);
                        Assert.AreEqual<Uri>(page1Uri, this.Frame.Source);
                        Assert.AreEqual<Uri>(page1Uri, this.Frame.CurrentSource);
                    }
                    else if (complete == 1)
                    {
                        // Verify Uri
                        Assert.AreEqual<Uri>(abcUri, args.Uri);
                        Assert.AreEqual<Uri>(abcUri, this.Frame.Source);
                        Assert.AreEqual<Uri>(abcUri, this.Frame.CurrentSource);

                        // Verify the instance was not re-used
                        Assert.IsFalse(Object.ReferenceEquals(firstInstance, frameContent));
                    }

                    complete++;
                };

            // Perform a navigation operation by Uri
            this.EnqueueCallback(() => Frame.Navigate(page1Uri));
            this.EnqueueConditional(() => complete == 1);

            this.EnqueueCallback(() => Frame.Navigate(abcUri));
            this.EnqueueConditional(() => complete == 2);

            // Success
            this.EnqueueTestComplete();
        }
Exemple #14
0
 /// <summary>
 /// 设置Uri映射
 /// </summary>
 private void SetMapUri()
 {
     if (RootFrame != null)
     {
         UriMapper uriMapper = new UriMapper();
         UriMapping uriMapping = new UriMapping();
         uriMapping.Uri = new Uri("/second/{x}/{y}/{z}", UriKind.Relative);
         uriMapping.MappedUri = new Uri("/SecondPage.xaml?x={x}&y={y}&z={z}",UriKind.Relative);
         uriMapper.UriMappings.Add(uriMapping);
         RootFrame.UriMapper = uriMapper;
     }
 }