How to disable bottom navigation view in xamarin android? - c#

I'm trying to disable my bottom navigation view in my activity but it didn't work. But when i try to hide it and show it, its worked fine. But to disable and enable it, it doesn't work. Btw I used android.support.design.widget.BottomNavigationView
This is the code i tried
BottomNavigationView bottomNavView = FindViewById<BottomNavigationView>(Resource.Id.bottom_navigation);
bottomNavView.Enable = true;
its not working and i don't know why :/

I am using NavigationView but I saw the same methods on BottomNavigationView (I declared it on my code). To disable the item you can do this:
navigationView = FindViewById<NavigationView>(Resource.Id.nav_view);//My navigationview
IMenuItem asd = (IMenuItem)navigationView.Menu.GetItem(2);
asd.SetEnabled(false);
If you want to remove items you can do this:
navigationView.Menu.RemoveItem(Resource.Id.nav_Cambiar_TPK);
navigationView.Menu.RemoveItem(Resource.Id.nav_nuevo);

Related

Switching pages loading the same left menu

I'm new to Xamarin and I don't understand too much things.
I've created an android app with the preinstalled left menu (hamburger menu) including navigation view. My content_page.xml is linked to MainActivity.cs and I run my code there. Now I want to create another page. So I add a layout element (like content_page) called second_content_page.xml and I link it to a new activity called SecondActivity.cs. Code behind works and I got no problems as far.
The problem is the second content page which doesn't show the menu items (there are lots of layouts about it). So I've tried to copy the code from MainAcitivity's OnCreate method:
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
SetContentView(Resource.Layout.activity_main);
//ToolBar
AndroidX.AppCompat.Widget.Toolbar toolbar = FindViewById<AndroidX.AppCompat.Widget.Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
DrawerLayout drawer = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close);
drawer.AddDrawerListener(toggle);
toggle.SyncState();
NavigationView navigationView = FindViewById<NavigationView>(Resource.Id.nav_view);
navigationView.SetNavigationItemSelectedListener(this);
But I run into many errors related to the toolbar that (as VS says) is loaded two times, so I thought this way to load the same menu was incorrect.
My question is: how to switch pages in the correct way using xml pages and not xaml?
It seems that you can use FlyoutPage, it contains flyout page and detail page and the menu will always display if you what.
Here is a guide about it:https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/flyoutpage
And here is an sample link:
https://github.com/xamarin/xamarin-forms-samples/tree/main/Navigation/FlyoutPage

Hide Navigation Bar Prism Xamarin

I have the following set in my view code behind
NavigationPage.SetHasNavigationBar(this, false);
and I have it also in the XAML
NavigationPage.HasNavigationBar="False"
However the navigation panel is still displaying when navigating with Prism and the follow code:
await NavigationService.NavigateAsync("NavigationPage/RecipeListPage");
Navigating with the absolute method such as:
NavigationService.NavigateAsync(new System.Uri("http://www.RecipeDatabase/RecipeListPage", System.UriKind.Absolute));
Fixes this issue. Not sure why its needed. Also hiding with just the XAML code as well is sufficient.
Enjoy.

how to enable and disable master detail page menu and gesture?

I want to enable and disable the bars and gesture of the master detail page (basically the whole menu) so that the user can't navigate when opening a certain page. I tried using a modal page to achieve this but I really need the toolbar menu of the navigation page.
How can I achieve that?
use IsGestureEnabled
IsGestureEnabled = false;
Setting the IsGestureEnabled property of the MasterDetailPage to true in the OnAppearing event and false in the OnDisappearing event of each DetailPage, seems giving the expected results.
if IsGestureEnabled = false; Property is working in Android. But not in iOS.you could use CustomRenderer ,you could refer to the workaround

Xamarin Forms masterdetail hide backbutton

I am working on Xamarin forms shared project with a master detail page. When I run the app the master detail page is the first item that loads yet it shows the back button which once clicked opens the navigation (master) drawer. This makes no navigation sense whatsoever! I have tried to hide the back button but have not been able to do this. Has anyone come across this and succeeded in doing this? I would prefer a programmatical solution rather than a xaml one.
I have tried adding the below code:
NavigationPage.SetHasBackButton(this, false);
But this doesn't work. I want to keep the toolbar as I will be adding my own menu items here but want the back button gone.
Try this:
NavigationPage.SetBackButtonTitle(this, string.Empty);
NavigationPage.SetHasBackButton(this, false);

LongListSelector interaction breaks when a popup is open in WP8

To dynamically place some content on a page in a Windows Phone 8 project, we use a popup with a grid to host the content.
When this page contains a LongListSelector control, the Tap interaction to stop scrolling no longer works. Swiping up and down works as expected.
The issue can be reproduced very easily by starting with a new Databound app and adding this piece of code in the page constructor:
private Popup p;
p = new Popup();
Grid grid = new Grid();
grid.Width = Application.Current.Host.Content.ActualWidth;
grid.Height = Application.Current.Host.Content.ActualHeight;
p.Child = grid;
p.IsOpen = true;
Using this code you can make the LongListSelector scrolling but a Tap does no longer work to stop the scrolling.
Has anyone seen this issue and found a solution or might this be a known issue with the LongListSelector?
The invisible Grid that you're putting over the LongListSelector (actually the whole page) is capturing the tap event and because the popup is not part of the visual tree the event doesn't bubble as you're expecting.
The anomaly here is that you can actually interact with the LLS at all.
The real question here isn't why this happens but why you'd do this? Obviously your reproduction is very simple but it's to a point that makes no sense.
What are you ultimately trying to achieve?
There are almost certainly more appropriate alternative ways to achieve your end goal.

Categories