Frage

I am developing Windows Phone 8 PhoneGap app. I want the App Bar to be dynamically created so that it will not be visible in initial page, and it will not have menu item 'LogOut' in Login page. I have an idea of achieving this by getting current URL of the webview and displaying the app bar accordingly. So, I would like to know how to get the current URL of the PhoneGap webview and create the app bar accordingly. I already went through http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394044(v=vs.105).aspx

War es hilfreich?

Lösung 2

URI currentURI = ((App)Application.Current).RootFrame.CurrentSource;

should return the url of the current view. This should be placed in the function where navigation is occurring so that is called every time the page is changed. You can then convert that to a string using the toString() function specific to the URI class and see if it matches the page url you are looking for. If it does then dynamically adjust the app bar. I am assuming you already know how to do this considering you went through the link given, but if you don't please comment.

Andere Tipps

I achieved the objective by handling the event through this.CordovaView.Browser.Navigated += Browser_Navigated; where Browser_Navigated function is as follows.

private void Browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            Console.WriteLine("Browser_Navigated:" + sender);

            String currentURL = "";
            Boolean isAbsolute = this.CordovaView.Browser.Source.IsAbsoluteUri;
            ApplicationBar = new ApplicationBar();
            ApplicationBar.Mode =ApplicationBarMode.Minimized;
            if (isAbsolute)
            {
                currentURL = this.CordovaView.Browser.Source.AbsoluteUri;



                ApplicationBarMenuItem clearCache = new ApplicationBarMenuItem();
                clearCache.Text = "Reset user settings";
                ApplicationBar.MenuItems.Add(clearCache);
                clearCache.Click += new EventHandler(OnClearCache);

                if (! currentURL.EndsWith("LoginSP.aspx")) 
                {
                    ApplicationBarMenuItem logOut = new ApplicationBarMenuItem();
                    logOut.Text = "Log out";
                    ApplicationBar.MenuItems.Add(logOut);
                    logOut.Click += new EventHandler(OnLogOut);
                }
            }
            else
            {
                currentURL = "x-wmapp1:" + this.CordovaView.Browser.Source.OriginalString;
                ApplicationBar.IsVisible = false;
            }

            Console.WriteLine("currentURL:" + currentURL);
        }

reference: https://github.com/dev-mobile/cordova-starter/blob/master/win7_cordova_starter/wp7_CordovaStarter/MainPage.xaml.cs

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top