I have a flyout page which I use to login. I store the username in the localsettings and its all fine up to this point. After the login I want the pagetitle of the page to be something like: "welcome: " + username. (where username is stored in the localsettings).
This works. But only after I reloaded the mainpage by for example going to another page and back again or when I close the entire app and start it again. It doesn't work right away after "login in" do to localsettings only being loaded when a page is started not when its already running.
Is there a way to "reload" the mainpage after the flyout closes? Is there something that I can execute when the mainpage gains focus? Might there be a method for regaining focus(if so I can't find it).
This is (a part of) my flyout page where i store the variables in my localsettings:
localSettings.Values["settingUserName"] = TbUserName.Text;
localSettings.Values["settingPassword"] = TbPassWord.Text;
*note : Frame.Navigate(typeof(page) does NOT work. since flyouts doesn't support that.
I found the solution, ill share it here if anybody else ever needs it.
In C# store apps there is something that checks if the screen got focus. To add this method just add this to the code of the page you want to check if it has focus (or just gained focus).
protected override void OnGotFocus(RoutedEventArgs e)
{
base.OnGotFocus(e);
}
Related
I want to use template 10 to develop my app, but I dont know how can I hide the back button once I pass from one page to another, like for example passing from a login page to my main page.
With template 10 it always show the back button, I know how to prevent from going back, but still I can see the damn back button on the shell, I dont wish to see it.
How could I hide it?
ClearHistory is located on the HamburgerButtonInfo as a DP and if that isn't enough you can thru the NavigationService call ClearHistory as well which looks like public void ClearHistory() => FrameFacade.BackStack.Clear(); in the source so you know what it actually calls...
I'm making a program that has a Form with a ChromiumWebBrowser in it. The navigation is done automatically. When webbrowser complete it's task, I'll dispose it, create a new webbrowser, add it to form, and load a new address.
But, when the new webbrowser was created and added to form, the program jumps in front of what ever other program is in the top with focus. Example: I start my program, press the button to start its task, open notepad to type some text and my program jumps in front of it when navigating to a new site.
Even when the window is minimized, it still steals focus from other open programs.
How do I prevent it stealing focus after it is created?
As #amaitland said, this looks like a bug.
Workarounds I've used are:
1) disable the browser. This will prevent the browser from receiving mouse/keyboard input, but it won't "grey-out" the control.
Browser1 = New CefSharp.WinForms.ChromiumWebBrowser(url)
Browser1.Enabled = False
2) Pass a callback .net function for when the page loads where you simply put the focus back to winforms by focusing on a label of your choice.
Label1.Focus()
Your Form need set: this.Topmost = false;
AND just set: this.BringToFront();
Add new browser to the form just like the function as follow:
private ChromiumWebBrowser AddNewBrowser(FATabStripItem tabStrip, String url)
{
if (url == "")
{
url = OpenUrl;
txtUrl.Select();
txtUrl.Focus();
}
else
{
tabStrip.Select();
tabStrip.Focus();
}
// ...
}
Hope has help to you. Thanks !
I am developing an app for Windows Phone 8 in VS2012 and My StartUp Project page is SetProfile.XAML which creates the profile for the first time, but if the user is entering the app second time, the page must not appear because there is already an existing profile.
So I have this code for the "Loaded" event handler, which checks if there is a created profile and if there is, navigates to MainPage page.
private void PhoneApplicationPage_Loaded_1(object sender, RoutedEventArgs e)
{
if (Flag.Contains("true"))
{
if (IsolatedStorageSettings.ApplicationSettings.Contains("player1"))
if (!(Flag.Contains("false")))
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
}
The problem is when I enter a second time, I see a blink of the SetProfile.XAML page then it navigates (it's like milliseconds), but I still can see it.
Is there any way I can make it faster so the user won't see it?
There is a very good blogpost about how to 'navigate' to a screen that is not always needed up on Shawn's blog here http://www.visuallylocated.com/post/2012/06/18/Using-a-custom-UriMapper-to-navigate-to-a-login-screen.aspx
The trick is to use a custom UriMapper class that checks all the info and determines the correct navigation uri.
You use this class in your app.xaml.cs - Application_Launching and Application_Activated
you see blink as you have used "Loaded" event,it loads page in run time and must not used unnecessary.
You must use "OnNavigatedTo" event for these normal scenarios.
This question may be possible duplicate of
WP8 back button go two steps back
My game page structure as follow
MainPage(Select New Game) - > Level1 Page(After complete 60 sec this page automatically goto next page->Alert page (it contain TryAgain-Home-Exit Buttons if user click TryAgain Button "Level1" Page Show)
My problem start here..
Now User in "Level1" user click phone back button it show the Alert Page . it's wrong
but correct way is from "Level1" to MainPage
I try following code in Level1 Page
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
RootFrame.RemoveBackEntry();
base.OnBackKeyPress(e);
}
I got error in RootFrame The name 'RootFrame' does not exist in the current context
Any one tell me where i made mistake and what code i need to add for RootFrame. this is my first Wp8 game app development. Thank You
I just had this same problem. The tutorial uses RootFrame.RemoveBackEntry();
The default is NavigationService.RemoveBackEntry();
I am currently working on an app for WP7 for my university, and need a temporary solution to a problem. Now this solution is, that I will be loading a webpage using the web browser control for WP7. For example: http://m.iastate.edu/laundry/
Now as you see on the webpage, there are certain elements I want to hide, for example the back button. For now, what I have done to handle the back button is something like this:
private void webBrowser1_Navigating(object sender, NavigatingEventArgs e)
{
// Handle loading animations
// Handle what happens when the "back" button is pressed
Uri home = new Uri("http://m.iastate.edu/");
// The the current loading address is home
// Cancel the navigation, and go back to the
// apps home page.
if (e.Uri.Equals(home))
{
e.Cancel = true;
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
}
Now that works beautifully, except for the part that there is a back button on the hardware.
So my second option is to completely hide the back button ONLY on that page, and not its children. So not on http://m.iastate.edu/laundry/l/0
I am still debating on just parsing the data and displaying it in my own style, but I'm not sure if that's completely needed seeing how the data needs constant internet service and is already in a well-put format. Plus, I feel like that would be a waste of resources? Throw in your opinions on that too :)
Thanks!
You should inject a script in the page with InvokeScript.
Here is the kind of Javascript code you need to remove the back button:
// get the first child element of the header
var backButton = document.getElementsByTagName("header")[0].firstChild;
// check if it looks like a back button
if(backButton && backButton.innerText == "Back") {
// it looks like a back button, remove it
document.getElementsByTagName("header")[0].removeChild[backButton];
}
Call this script with InvokeScript:
webBrowser1.InvokeScript("eval", "(function() { "+ script +"}()");
Warning: IsScriptEnabled must be set to true on the web control
If the removal of the back button depends of the page, just test the navigating URI in C# and inject the script if neeeded.