Remove 2 Entries from Navigation Journal - wpf

In my windows phone 8 app i have to check if user is already login or not before navigating to different pages. If user is not logged in i navigate the user to Login.xaml from where user chooses either login from Facebook or twitter or cancel.
Now when user successfully logs in i navigate the user to appropriate page. My question is how to remove those potential 2 pages (login.xaml and facebook/twitter login)?
NavigationService.BackStack is IEnumerable :(
does anyone has a work around?

If it is the same as using the WPF NavigationService then you can use RemoveBackEntry after you have navigated to the new page.
Update:
If you are using code such as
if (!user.IsLoggedIn)
{
NavigationService.Navigate(new Login());
}
Then you can remove the back entries before anyone has a chance to see them
if (!user.IsLoggedIn)
{
NavigationService.Navigate(new Login());
//Hide back entry
NavigationService.RemoveBackEntry();
}
However if you are unable to do this, for example when you end up with a Facebook/twitter url in the back entry, then instead subscribe to the Navigated event and then remove them
public Login()
{
NavigationService.Navigated += HideEntriesOnNavigated;
}
void HideEntriesOnNavigated(object sender, NavigationEventArgs e)
{
if (IsFacebookLogin(e.Url)
|| IsTwitterLogin(e.Url)
|| IsAppLoginPage(e.Url))
{
NavigationService.RemoveBackEntry();
}
}

Related

Login form is shown for a couple of second in iOS

I have a login form & once the user logged in, this form should not be shown until user log out. I have used getFirstFormName method to do this and it works fine in android. But in iOS although the user has already logged in, the login form is shown for a couple of second.
#Override
protected String getFirstFormName() {
loginToken = Preferences.get("loginToken", null);
if (loginToken != null) {
return "MenuForm";
} else {
return "Login";
}
}
What you are seeing is a static image of the 1st screen of your app, you need to add a splash screen to your app to be the first screen.

Silverlight windows phone 8.1 FileOpenPicker for all files Continue not working

i create silverlight windows phone 8.1 project and i need to choose all kind of file from windows phone
i used FileOpenPicker for choose the file it redirect correctly and i can choose the file this is my code
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.List;
openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
openPicker.FileTypeFilter.Add("*");
openPicker.PickMultipleFilesAndContinue();
And i follow this msdn for receiving select
In my case
if i selecting file and come back to the app its every thing working
if i without select any file and come back using mobile hardware back button my app come to home screen. but it need to stay file picker page
my first page
when i press mobile hardware back button in above screen the page redirect to my first page it need to stay in my second page
thanks
Finally i got the answer and avoid redirection
bool reset;
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
if(reset && e.uri.tostring().Equals("MainPage.xaml"))
{
e.Cancel = true;
reset = false
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
reset = e.NavigationMode == NavigationMode.Reset;
}

CefSharp load a page with browser login

I need to ebed a web browser in a Wpf app, I tried with the one from the toolbox but get some issues and went to CefSharp.
public MainWindow()
{
InitializeComponent();
BrowserSettings settings = new BrowserSettings();
Cef.Initialize(new CefSettings());
CefSharp.Wpf.ChromiumWebBrowser webBrowser = new CefSharp.Wpf.ChromiumWebBrowser();
licence_grid.Children.Add(webBrowser);
webBrowser.Address = "http://myurlToLoad the page";
}
The problem is when I used a normal url the page load.
But when I used the url I intend to use and whith which the user enter his user and password in a browser pop up (I mean not a pop up from the website) . I get an error with this page take yoo much time to load and nothing else.
Can someone give me some tracks to follow...
Thanks
It sounds like the popup you are referring to is in fact the site prompting for basic authentication.
In that case you need to provide an IRequestHandler.GetAuthCredentials handler.
As the question & answer is very old and i would like to give the latest update on this solution, there is slight change as per original solution suggested.
anybody consuming cefsharp need to implement the authentication dialog. and changes in method is
bool IRequestHandler.GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy,
string host, int port, string realm, string scheme, IAuthCallback callback)
{
//NOTE: If you do not wish to implement this method returning false is the default behaviour
// We also suggest you explicitly Dispose of the callback as it wraps an unmanaged resource.
// shyam - original implemenation.
//callback.Dispose();
//return false;
bool handled = false;
// Instantiate the dialog box
AuthDialog dlg = new AuthDialog(host); // create new dialog with username and password field.
// Open the dialog box modally
dlg.ShowDialog();
if (dlg.DialogResult == System.Windows.Forms.DialogResult.OK)
{
// The user did not cancel out of the dialog. Retrieve the username and password.
callback.Continue(dlg.UserName,dlg.Password);
handled = true;
}
return handled;
}

WP8 Webbrowser, stop navigation without killing page

I have an app that uses a web browser control to navigate a website. When the user clicks on a hyperlink that will take them out of the site I want to be able to stop the navigation. I tried.
void wgBrowser_Navigating(object sender, NavigatingEventArgs e)
{
if (!e.Uri.AbsoluteUri.Contains(BASEURL))
{
e.cancel = true;
return;
}
progressPB.Visibility = Visibility.Visible;
}
This does in fact stop the navigation, but it kills the page causing a navigation error message to appear in the webbrowser.
I have tried a few things including a wgBrowser.Goback() after navigation, but that is not a real "back", and causes the page to reload complete losing data the user previously entered.
Any help will be greatly appreciated.
Thanks you.
Are u tried IsolatedStorageSettings? Because using IsolatedStorageSettings store the data will be better when the page is navigate.
Example:
private void tbUserName_SelectionChanged(object sender, RoutedEventArgs e)
{
if (appSetting2.Contains("MainPage2"))
{
appSetting2["MainPage2"] = this.tbUserName.Text;
}
else
{
appSetting2.Add("MainPage2", this.tbUserName.Text);
}
}
Use can use the InvokeScreipt method over WebBrowser control to stop page navigation.
yourWebBrowser.InvokeScript("eval", "document.execCommand('Stop');");

C# properties settings works from the second time on

Here's the problem: I've published an app made with Windows Forms with ClickOnce. Therefore, I can't show Terms of Service before install. The client decided to show some Terms of Service page after the install, and if the user agreed with the terms by pressing the button, show the main app. Problem is, after install the app shows the ToS, the user accepts, and after the first restart the user is shown the ToS again! If he accepts, the next time the user opens the app (either after a restart or after the app is closed and opened again) this problem will no longer appear, i.e. if the user agreed to the ToS the main app will show up, without asking the ToS.
The code defining the tos in settings:
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("False")]
public bool tos {
get {
return ((bool)(this["tos"]));
}
set {
this["tos"] = value;
}
}
The code that checks for ToS when the app starts:
bool tosB = Properties.Settings.Default.tos;
if (!tosB)
{
this.tab_control.SelectTab(this.TOS_PAGE);
this.richTextBox1.Rtf =
global::MyAppName.Properties.Resources.terms_and_conditions;
}
else
{
check_connectivity();
}
The code that runs when the user cliks the I agree button:
private void button2_Click(object sender, EventArgs e)
{
Properties.Settings.Default.tos = true;
Properties.Settings.Default.Save();
Microsoft.Win32.RegistryKey key =
Microsoft.Win32.Registry.CurrentUser.OpenSubKey(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
key.SetValue("My App Name", Application.ExecutablePath.ToString());
check_connectivity();
}

Resources