Code Monkey home page Code Monkey logo

Comments (13)

allenmoatallen avatar allenmoatallen commented on August 20, 2024 11

@viniciusou Below is the class I currently use.

Example:

var masterDetail = new ThemedMasterDetailNavigationContainer();
masterDetail.Init("Menu", "slideout.png");

masterDetail.AddPageWithIcon<MyViewModel>("Home", "slideout.png");
public class MenuItem
    {
        public string Title { get; set; }
        public string IconSource { get; set; }
    }
public class ThemedMasterDetailNavigationContainer : FreshMasterDetailNavigationContainer
    {
        List<Models.MenuItem> pageIcons = new List<Models.MenuItem>();

        public void AddPageWithIcon<T> (string title, string icon = "", object data = null) where T: FreshBasePageModel
        {
            base.AddPage<T>(title, data);
            pageIcons.Add(new Models.MenuItem
            {
                Title = title,
                IconSource = icon
            });
        }

        protected override void CreateMenuPage(string menuPageTitle, string menuIcon = null)
        {
            var listview = new ListView();
            var _menuPage = new ContentPage();
            _menuPage.Title = menuPageTitle;
            _menuPage.BackgroundColor = Color.FromHex("#c8c8c8");

            listview.ItemsSource = pageIcons;

            var cell = new DataTemplate(typeof(ImageCell));
            cell.SetValue(TextCell.TextColorProperty, Color.Black);
            cell.SetBinding(ImageCell.TextProperty, "Title");
            cell.SetBinding(ImageCell.ImageSourceProperty, "IconSource");


            listview.ItemTemplate = cell;
            listview.ItemSelected += (sender, args) =>
            {
                if (Pages.ContainsKey(((Models.MenuItem)args.SelectedItem).Title))
                {
                    Detail = Pages[((Models.MenuItem)args.SelectedItem).Title];
                }
                IsPresented = false;
            };

            _menuPage.Content = listview;

            var navPage = new NavigationPage(_menuPage) { Title = "Menu" };

            if (!string.IsNullOrEmpty(menuIcon))
                navPage.Icon = menuIcon;

            Master = navPage;

        }

        protected override Page CreateContainerPage(Page page)
        {
            var navigation = new NavigationPage(page);
            navigation.BarTextColor = Color.White;

            return navigation;
        }
    }

menuicon

from freshmvvm.

viniciusou avatar viniciusou commented on August 20, 2024 1

Thank you @rid00z , I will follow your advice. I'm trying to implement menu icons on a MasterDetailContainer using Material Design pattern.

I watched your n+ videos and they were really helpful. Great work done on FreshMvvm!

from freshmvvm.

rasmuschristensen avatar rasmuschristensen commented on August 20, 2024 1

You could extend the class with a bindable property to support databinding like this

public static readonly BindableProperty ItemTemplateSelctorProperty =
           BindableProperty.Create (nameof (MenuItemItemTemplate), typeof (DataTemplate), typeof (StyledMDContainer), default (DataTemplate));

from freshmvvm.

olexale avatar olexale commented on August 20, 2024

Current FreshMasterDetailNavigationContainer implementation use page names only and there is no easy way to add icons there. Of course you may override CreateMenuPage for Main page initialisation and create new AddPage method with icon parameter, but I would recommend just to create a custom navigation container. Fortunately with FreshMvvm this is super easy. You may use FreshMasterDetailNavigationContainer source code as a reference.

from freshmvvm.

allenmoatallen avatar allenmoatallen commented on August 20, 2024

The source code uses some internal members. I ended up just overriding those two methods. Is it possible for this capability to be added?

from freshmvvm.

DNF-SaS avatar DNF-SaS commented on August 20, 2024

Yes, FreshBasePageModel.CurrentNavigationServiceName is an internal string (which is set in FreshMasterDetailNavigationContainer.AddPage).
Unfortunately, it's not accessible when creating an own NavigationContainer.
Can you please make it public / wrap a settable property around it?
Thanks.

from freshmvvm.

viniciusou avatar viniciusou commented on August 20, 2024

Hello @allenmoatallen, I had the same question when started to work with MasterDetailContainer these days. Could you share which approach have you used to get menu item icons supported in a MasterDetailContainer? Thanks.

from freshmvvm.

rid00z avatar rid00z commented on August 20, 2024

Hi All

If you inherit from FreshMasterDetailNavigationContainer then you'll be able to implement any MasterPage that you would like. You can also look at the container for a reference to completely do your own.

I'm planning to do some more videos on more advanced navigation in FreshMvvm. Just need to find the time.

from freshmvvm.

chosenonehacks avatar chosenonehacks commented on August 20, 2024

Hi all

I'm planning to do some more videos on more advanced navigation in FreshMvvm. Just need to find the time.

Please find :)
Thanks

from freshmvvm.

viniciusou avatar viniciusou commented on August 20, 2024

Awesome @allenmoatallen,

I've tested and adapted the code to my sample app and it's working perfectly!

Thanks a lot.

from freshmvvm.

allenmoatallen avatar allenmoatallen commented on August 20, 2024

Glad I could help!

from freshmvvm.

rasmuschristensen avatar rasmuschristensen commented on August 20, 2024

Great example @allenmoatallen . Is override still the way to go i you want to customize style like colors and fonts?

from freshmvvm.

EmilAlipiev avatar EmilAlipiev commented on August 20, 2024

@allenmoatallen thanks for that. it works fine but when I extend this using viewcell with some grid layout inside viewcell, I am able to extend as I want. Only problem I have is when I select and item from the list, it causes a small flash on the screen and navigates to the page and hides side bar. Has anybody experienced something like that? maybe it is because my layout became so heavy or side bar is too fast disappears.

from freshmvvm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.