How do I preserve a hamburger menu when linking from a contentpage? - ios

I've been using the MasterPageDetail approach in creating a hamburger menu for my Xamarin Forms app. The menu itself works fine as taken from the Xamarin documentation https://developer.xamarin.com/samples/xamarin-forms/Navigation/MasterDetailPage/. What I noticed was that if I create a simple link to a page in one of my views, the hamburger menu and it's icon are replaced with a back button.
What I would like to know is how to create a link in a content page that will preseve my hamburger menu instead of showing a back button. Any link you click from the MasterPage takes you to the corrosponding view but you can still see the hamburger menu, if you click a link within one of the pages however you are taken to the page but with a back button instead. It's causing a very confusing navigational experience for my users.
The following code demonstrates how the manu is created in the hamburger menu just now.
public partial class MasterPage : ContentPage
{
public ListView ListView { get { return listView; } }
public MasterPage()
{
InitializeComponent();
//var master = new MasterPage();
var masterPageItems = new List<MasterPageItem>();
masterPageItems.Add(new MasterPageItem
{
Title = "Dashboard",
IconSource = "dashboard-icon-24.png",
TargetType = typeof(Dashboard)
});
listView.ItemsSource = masterPageItems;
}
So that works perfectly, you can navigate around and the hamburger menu is there all the time.
Within my view called 'dashboard' I added some link to hope to those same pages that are in my hamburger menu, I did so int he following way:
<Button Text="Information" Clicked="informationClick" />
The code for this is as follows:
private void informationClick(object sender, EventArgs e)
{
Navigation.PushAsync(new Information());
}
When you click on this link however you lose the hambuger menu and it's repalced with the back button instead. I want to preserve the hamburger menu, does anyone know how I can do this from my content page?

You must replace the "Detail" property of your MasterDetail page with a new NavigationPage containing the page you are linking.
Something like that:
(App.Current.MainPage as MasterDetailPage).Detail = new NavigationPage(new ContactsPage());
This is not really clean but it makes the idea.

Related

Removing back arrow in navigation bar keeping back button title

I have xamarin forms ios application,where I need to remove the back arrow in the navigation bar but the title should be displayed and when user clicks on on that back button title it should navigate to previous view.
I tried using `
NavigationPage.SetBackButtonTitle(this, "Cancel");
NavigationPage.SetHasBackButton(this, false);
But the back arrow is still displaying,is there any why to have only the text Cancel without <symbol?
I solved my issue by adding a custom renderer as follows
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
this.NavigationController.TopViewController.NavigationItem.LeftBarButtonItem =new UIBarButtonItem(“Cancel”, UIBarButtonItemStyle.Plain, (sender, args) => { });
}
In your AppDelegate.cs file, in the FinishedLaunching method add these lines:
UINavigationBar.Appearance.BackIndicatorImage = new UIImage();
UINavigationBar.Appearance.BackIndicatorTransitionMaskImage = new UIImage();
This will however, remove it for every page. If you want it for just one page I would suggest like EvZ already mentioned: use a modal page or find another way.
Another way is to set the above lines to null which will restore the normal arrow. But this would mean implementing a custom renderer, dependency service or similar.
Remove navigation-bar and use image/header on navigation place and write into image/Header into navigation title...
image onclick event into write back command

Xamarin forms Master detail Icon

I am trying to add an image next to the hamburger menu in my app. I am using a master detail page and it renders fine in ios and android. I tried using setting the icons for the detail pages. but the icons never showed. How do I achive this. I am looking to add an image similar to the amazon app.
I checked out this app on my phone and it uses a lot of custom constructions that aren't supported by out of the box Xamarin Forms controls. Something like the back arrow next to the hamburger menu is not a standard thing (on iOS at least). Also looking at the actual menu that the hamburger button triggers it becomes clear that its not an out of the box hamburger menu. Theirs pops over the content instead of sliding it out of view as the built-in one does.
More than likely they implemented their own hamburger menu and navigation structure which gave them the freedom to add buttons next to it. If you want to achieve this with out of the box controls you will most likely need custom renderers for each platform to create a replica of this navigation structure.
What is built-in in Xamarin Forms is that you can set the page title to an image instead of text by using the NavigationPage.SetTitleIcon method, which could be used to achieve what you want:
public class MyPage : NavigationPage
{
public MyPage ()
{
var myContentPage = new MyContentPage (Color.White);
this.Push (myContentPage);
var s = "icon.png";
NavigationPage.SetTitleIcon (myContentPage, s);
}
}
Even then, this is limited in functionality. If you want to fiddle with the alignment of the image e.g. you would also need to resort to a custom renderer.

Display views side by side

I am very new to MVC hence maybe its a basic problem.
I have created a controller called HomeController which would have a view displaying a navigation panel which behaves like a menu but should always be visible as the folders in Windows Explorer. On clicking on an item, I want to load another view to the right hand side (similar to master detail). Each item has a view and a model. To load the navigation panel I have the following code
#foreach (var service in Model.Services)
{
#Html.ActionLink(service.Label, "Details", new { serviceName = service.ServiceName })
}
This code works fine but is code opens another view and my navigation list disappears. Please guide how to open my Details view along with the Home view
You need to use ajax to do this.
Split your page into 2 parts. The left - link container div and right preview div. When you click on a link, using ajax to call that link and update the DOM (preview div) of the same page.
<div>
<div class="pageLeftMenuContainer">
#foreach (var service in Model.Services)
{
#Html.ActionLink(service.Label, "Details",
new { serviceName = service.ServiceName },new { #class="ajaxLink"})
}
</div>
<div class="pageRight" id="preview"></div>
</div>
Now listen to the click event on the links with the css class ajax link and load the preview div. You can use jquery load() method.
$(function(){
$(".ajaxLink").click(function(e){
e.preventDefault(); // prevent the normal link click behavior
$("#preview").load($(this).attr("href"));
});
});

How to make content navigation button (remains pressed when clicked) in Vaadin

I created basic vertical layout that work as side menu and now I want to place some buttons in it. Few of them gonna work as common side menu buttons, they just change page content so I want to mark that they are clicked in some way, how can I achive that? Or maybe there is better way?
As stated in the 5th version of Vaadin7 manual, you can attach an event listener to the Button.
button.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
// show the button has been clicked with a CSS class:
button.addStyleName("v-button-clicked");
}
});
Don’t forget to define the v-button-clicked class. Of course you’re free to add the class of your liking through the .addStyleName() method.

Remove menu item on Blackberry

In my Blackberry application, I have screen with few menu items (created by myself in makeMenu()).
On this screen, sometimes I should remove two of this menu items.
But menu.deleteItem() method does not work.
How i can remove menu item in application menu, without recreate new instance of screen? Is it real for already constructed menu? Or mb I should refresh menu/screen someway?
Thanx.
The menu is drawn at the point it's selected so all I do is set conditions on anything that's not static, example below:
protected void makeMenu( Menu menu, int instance ) {
menu.add(staticMenuItem);
if (condition) menu.add(dynamicMenuItem);
}

Resources