This is a migrated thread and some comments may be shown as answers.

How to change RadSideDrawer MainContent

1 Answer 199 Views
SideDrawer
This is a migrated thread and some comments may be shown as answers.
kostas
Top achievements
Rank 1
kostas asked on 07 Jun 2017, 02:35 PM

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?

1 Answer, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 07 Jun 2017, 07:09 PM
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
Tags
SideDrawer
Asked by
kostas
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Share this question
or