How to change RadSideDrawer MainContent

2 posts, 0 answers
  1. kostas
    kostas avatar
    1 posts
    Member since:
    Mar 2017

    Posted 07 Jun Link to this post

    I am kind of new in xaml and Telerik controls.

    I am using RadSideDrawer for my ContentPage.Content.

    I would like to change RadSideDrawer MainContent on a button Click.

    this is my code:

    var incidentButton = new Button
                {
                    Text = "Incident Button",
                    WidthRequest=30
                };
     
                incidentButton.Clicked += OnIncidentButtonClicked;
     
                var aboutButton = new Button
                {
                    Text = "About Button",
                    WidthRequest = 30
                };
     
                aboutButton.Clicked += OnAboutButtonClicked;
     
                var drawerContent = new StackLayout();
                drawerContent.Children.Add(new Button { Text="alfa"});
                drawerContent.Children.Add(new Button { Text = "beta" });
     
                var mainContent = new StackLayout();
                
                mainContent.Children.Add(incidentButton);
                mainContent.Children.Add(aboutButton);
     
                var sideDrawer = new RadSideDrawer
                {
                    MainContent = mainContent,
                    DrawerContent = drawerContent,
                    DrawerLength = 200
                };
                Content = sideDrawer;
     
     
                void OnIncidentButtonClicked(object sender, EventArgs e)
                {
                    //Here i would like to change the sideDrawer.MainContent to another Content
     
                }

     

    any suggestions?

  2. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    419 posts

    Posted 07 Jun Link to this post

    Hello Kostas,

    I've written you a demo (find it attached). When you click a button in the DrawerContent, it updates the MainContent.

    Here's the code that performs the update:

    private void SetMainContent(string contentType)
    {
        switch (contentType)
        {
            case "Mail":
                drawer.MainContent = new MyMailView();
                break;
            case "Calendar":
                drawer.MainContent = new MyCalendarView();
                break;
        }
    }


    The key takeaway is the MainContent needs to be set using a type of View.

    From what it looks like you're trying to do, just create your content (Grid/stackLayout/etc) first, and when it's done then set the SideDrawer.MainContent with it. 

    I don't see anywhere you set MySideDrawer.MainContent = XXXX, change your approach to what you see in my demo and it should work as expected.

    Regards,
    Lance | Tech Support Engineer, Sr.
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top