Pop a page from stack - xamarin

I am trying to navigate from Home Page(in shared code) to Detail Page(in the droid,native code). I want to remove the Detail Page and go back to the Home Page when someone press the Accept button. Navigation.PopAsync() does not work for me.

I am trying to navigate from Home Page(in shared code) to Detail Page(in the droid,native code).
As I understand, your Detail Page(in the droid,native code), it's an Activity. You need using DependencyService to open an Activity from Xamarin.Forms.
You could read my answer about Start an Android activity in Xamarin Forms
.
I want to remove the Detail Page and go back to the Home Page when someone press the Accept button.
You just need to close the newly opened Activity, for example :
public class NativeActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.native_layout);
Button native_bt = FindViewById<Button>(Resource.Id.native_bt);
native_bt.Click += (s, e) =>
{
//close the current Activity and go back to the Home Page.
this.Finish();
};
}
}

Related

Xamarin Forms WebView open external link

I have a webview inside my application and when an external link is clicked (that in normal browser is open in a new tab), I can't then go back to my website.
It is possible when a new tab is open to have the menu closed that tab like Gmail do ?
The objective is that, whenever a link is clicked, the user would have the choice to choose which option to view the content with, e.g. Clicking a link would suggest open youtube app or google chrome. The purpose is to appear the google chrome option
Or what suggestions do you have to handle this situation ?
If I understood you correctly, you want to have the option to select how to open the web link - inside your app, or within another app's (browser) context.
If this is correct, then you can use Xamarin.Essentials: Browser functionality.
public async Task OpenBrowser(Uri uri)
{
await Browser.OpenAsync(uri, BrowserLaunchMode.SystemPreferred);
}
Here the important property is the BrowserLaunchMode flag, which you can learn more about here
Basically, you have 2 options - External & SystemPreferred.
The first one is clear, I think - it will open the link in an external browser.
The second options takes advantage of Android's Chrome Custom Tabs & for iOS - SFSafariViewController
P.S. You can also customise the PreferredToolbarColor, TitleMode, etc.
Edit: Based from your feedback in the comments, you want to control how to open href links from your website.
If I understood correctly, you want the first time that you open your site, to not have the nav bar at the top, and after that to have it. Unfortunately, this is not possible.
You can have the opposite behaviour achieved - the first time that you open a website, to have the nav bar and if the user clicks on any link, to open it externally (inside a browser). You have 2 options for this:
To do it from your website - change the a tag's target to be _blank like this;
To do it from your mobile app - create a Custom renderer for the WebView. In the Android project's renderer implementation, change the Control's WebViewClient like so:
public class CustomWebViewClient : WebViewClient
{
public override bool ShouldOverrideUrlLoading(Android.Webkit.WebView view, IWebResourceRequest request)
{
Intent intent = new Intent(Intent.ActionView, request.Url);
CrossCurrentActivity.Current.StartActivity(intent);
return true;
}
}

Windows phone 8.1 navigation

In my app, I have 3 pages:
MainPage
Page2
Page3
I want to go back from Page 3 to Page2 and to MainPage by Back device button.
So How should I do it?
Help me, please!
Navigation in WP 8.1 is totally different from the WP8, where here you only have to use Frame.Navigate and then give the Uri.
A perfect reference would be this.
Hope it helps!
Create an event for the hardware event like this:
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
And then handle the event accordingly:
void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
Frame.Navigate(typeof(MainPage)); // page you want to navigate to
e.Handled = true;
}
Hope this helps

How can i use NavigationServices in Application_Activated windows phone 7?

im developin an app for wp7 that it holds pictures and notes with password login. But when app running if user press windows button app is running at background and if user press back button it resumes without asking password again.
i tried to Navigate when app activated but i couldnt manage it in Application_Activated method. is there a way to do that? Or could you advice me sth else that solve my problem.
ty.
here is my code im using to navigate,
(Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
I got around this issue by using UserControls on the MainPage, showing one if the user had not yet logged in and the other if they had, I set these controls up to show/hide based on certains states in the MainPage and then bind that to the MainViewModel:
private void Application_Activated(object sender, ActivatedEventArgs e)
{
// Ensure that application state is restored appropriately
....your code here to load stuff...
App.ViewModel.MainPageState = "ShowThemTheLogin";
}
}

How to go to main menu on a button click in WP7

I have a button in the main page and on the click of it i want to exit the app and return to the phone's main menu page. My concern is that i cannot use CancelEventArgs for button_click event and another concern is that this is the first page in theNavigation stack, so Navigetion.goBack is false. Suggestions and help are welcome.
private void btnDeclineClick(object sender,RoutedEventArgs e)
{
exitApplication();
}
public void exitApplication()
{
try
{
NavigationService.CanGoBack.Equals(true);
if (NavigationService.CanGoBack)
{
NavigationService.GoBack();
}
}
catch(Exception e)
{
Logger.log(TAG, e.Message);
}
}
Programmatically exiting the application is not supported and against the certification requirements. I agre with Praetorian that you should just not have a Decline button or have it simply cover the application UI with some non-interactive content.
The only supported mechanisms for exiting the application are for the user to press the back button or navigating forward out of the application using the home/windows button or any launcher and then being killed by the OS.
Is this are you facing problem of exiting application programmatically ??
If yes you can do that without worrying which page user into currently
For exiting programmatically you can check this my another post answer.

"Don't Allow" and "Allow" buttons always off-screen on WP7 Facebook OAUTH browser control

I've developed a WP7 client that uses the Facebook C# SDK, using OAUTH and the web browser control.
Everything works fine except that on the page where the user is requested to accept/reject the access permissions I am asking for, the "Don't Allow" and "Allow" buttons are off the bottom of the browser's screen, and it isn't obvious that the user must scroll down to click on them.
I've tried using all the different display modes (touch, wap, page, popup) and "page" is the only one that shows the buttons on the same page, but then the fonts are tiny. I've also tried different sizes for the browser control.
The example in the SDK has the same behavior.
Has anyone found a work-around for this?
The solution I have found is to use Javascript to change the CSS properties for the element:
private void FacebookLoginBrowser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
// check for when this approve page has been navigated to
if (FacebookLoginBrowser.Source.AbsolutePath == "/connect/uiserver.php")
{
showBrowser();
// do the script injection on the LoadCompleted event - doing it here will appear to work when you have a fast connection, but almost certainly fails over 3G because the elements aren't ready in time to be modified
FacebookLoginBrowser.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(FacebookLoginBrowser_LoadCompleted);
}
// etc ...
}
void FacebookLoginBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
FacebookLoginBrowser.LoadCompleted -= FacebookLoginBrowser_LoadCompleted;
// Facebook will likely change this and break our code soon, so make sure you anticipates this
try
{
FacebookLoginBrowser.InvokeScript("eval", "document.getElementById('platform_dialog_bottom_bar').style.position = 'relative';document.getElementById('platform_dialog_bottom_bar').style.top = '-60px';");
}
catch
{
// TODO: display instruction to scroll down if we ever end up here
}
}
I hope that helps. Feel free to contact me if you run into problems
I haven't tried this, but could you use the WebBrowser control's Scale(SizeF) method to change the zoom level of the page?

Resources