I have implemented the swiping feature using SwipeGestureRecognizer on my homepage. But the problem is the home page is a child of a MasterDetailPage. So when I swipe to left in the homepage, the navigation drawer is also coming to UI. I have tried like below to stop showing navigation drawer on UI when doing SwipeGestureRecognizer using MessagingCenter, but no luck!!!
On Homepage
public void Swipe(object sender, EventArgs e)
{
MessagingCenter.Send<HomePage>(this, "HomePageSwipe");
//code for swipe
}
On MasterDetailPage Constructor
MessagingCenter.Subscribe<HomePage1>(this, "HomePageSwipe", (sender) =>
{
IsPresented = false;
NavigationPage.SetHasNavigationBar(this, false);
});
Is there any way to fix this?
I believe this behavior occurs only on ios. To disable this, you need to add this to the OnAppearing() method
if (Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.iOS)
{
IsGestureEnabled = false;
}
Related
I'm changing the orientation(Landscape/Portrait) forcefully for one screen.
For that, I used IsGestureEnabled property.
That property is not working on iOS 16 or above versions.
CODE:
protected override void OnDisappearing()
{
SetGestureEnabled(true);
base.OnDisappearing();
}
protected override void OnAppearing()
{
SetGestureEnabled(false);
base.OnAppearing();
}
private void SetGestureEnabled(bool isSet)
{
if (Application.Current.MainPage is MasterDetailPage masterDetailPage)
{
masterDetailPage.IsGestureEnabled = isSet;
}
}
Please help me to resolve this issue.
MasterDetailPage is obsolete. Try using FlyoutPage instead.
FlyoutPage also has IsGestureEnabled property which could disable or enable the swipe gesture. The default value is true. you could use almost the same code in your question
if (Application.Current.MainPage is FlyoutPage flyoutPage)
{
flyoutPage.IsGestureEnabled = true;
}
For more info, you could refer to Xamarin.Forms FlyoutPage
I am using Rg.Plugins.Popup NuGet package for showing pop up page. When clicking the android device back button the pop-up page is not hiding, it only closes the content pages. I am working on a .Net standard project.
Versions:
Rg.Plugins.Popup - 1.1.5.180
Xamarin Forms - 3.3.0.967583
Pop-up Page Codes
protected override bool OnBackButtonPressed()
{
return base.OnBackButtonPressed();
}
protected override bool OnBackgroundClicked()
{
return base.OnBackgroundClicked();
}
BackgroundClicked closing the pop-up page, but the device back button pressed not closing the pop-up page.
For Android back button issues handle on 'OnBackPressed',
public override void OnBackPressed()
{
if (Rg.Plugins.Popup.Popup.SendBackPressed(base.OnBackPressed))
{
// Do something if there are some pages in the `PopupStack`
}
else
{
// Do something if there are not any pages in the `PopupStack`
}
}
I tried to intercept the software back button in Android. I follow several samples that adds these:`
protected override void OnPostCreate(Bundle savedInstanceState)
{
var toolBar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolBar);
base.OnPostCreate(savedInstanceState);
}
protected override void OnResume()
{
Android.Support.V7.Widget.Toolbar toolbar = this.FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
if (toolbar != null)
SetSupportActionBar(toolbar);
base.OnResume();
}
Then use the OnOptionItemSelected to get the software back button event.
But this didn't work because, for me the first page of the app is login page that does not belong to NavigationPage. After the successful login, I change the Application.Current.MainPage to the root application page that is a NavigationPage. But it is too late, the OnPostCreate or OnResume already been called and the FindViewById(Resource.Id.toolbar) return null.
Any suggestion?
I dont understand whether you are asking xamarin.forms or xamarin.android.
For xamarin.forms
You can navigate from Login Page to Mainpage like this
Navigation.InsertPageBefore(new MainPage(), this);
Navigation.PopAsync();
And In your App.xaml.cs
MainPage = new NavigationPage(new Login());
I have set up a FreshTabbedNavigationContainer with 5 pages.
Within the 5th tabbed page which is a SettingsPage where there is a way to display and AboutPage that is displayed via the SettingsPageModel like this
public Command AboutCommand
{
get
{
return new Command(() =>
{
CoreMethods.PushPageModel<AboutPageModel>();
});
}
}
When the user navigates away by selecting another tab, this other tab is displayed correctly.
If the user selects the SettingsPage via the tab, then the child AboutPage is automatically displayed.
I want to remove AboutPage from the navigation stack when another tab page is selected.
I have tried this in the AboutPage.xaml.cs
protected override void OnDisappearing()
{
base.OnDisappearing();
((AboutPageModel)BindingContext).CoreMethods.RemoveFromNavigation();
}
This works BUT if the back button is pressed on the app when in the AboutPage then it has already been removed from the navigation stack, and the app crashes.
How can I check if a PageModel is still in the navigation stack?
I have managed to resolve the problem :)
In the App.xaml.cs file in the App constructor where I create the FreshTabbedNavigationContainer, after setting the MainPage
MainPage = tabbedNavigation;
I then add the following code
tabbedNavigation.CurrentPageChanged += (sender, e) => {
tabbedNavigation.PopToRoot();
};
It works perfectly.
I have a Tabbed Page Xamarin Form application that I am trying to customize. I am migrating from an IOs only app to all platforms. In iOS there are a couple function that I used ViewDidDisappear(), ViewDidAppear() and ViewDidLoad();
The application today loads the tabbed page as follows:
{
Children.Add(new MyPage1());
Children.Add(new MyPage2());
Children.Add(new MyPage3());
Children.Add(new MyPage4());
}
Each of the child pages are declared as follows all inheriting from ContentPage.
class MyPage1: ContentPage
{
…
protected override void OnAppearing()
{
base.OnAppearing();
Content = SomeContentPage;
}
}
The problem that I am running into is that the OnAppearing() is called for all pages when only MyPage1 is currently displayed. I need to know when each child page is loaded.
I have read about message center but I am not sure how to implement it in this particular case. Would the message center be the best solution for this?
How do I implement a solution that will allow me to know which of the four pages is displayed?
Possible workaround would be to override OnCurrentPageChanged in your TabbedPage.
protected override void OnCurrentPageChanged()
{
base.OnCurrentPageChanged();
if ( CurrentPage is YourContentPage page)
{
page.YourCustomCode();
}
}
On the main TabbedPage, after you've added child pages, setting the CurrentPage property to null should fix the problem.