Forum Xamarin Xamarin.Forms

Shell - Page with complex constructor

DinoNovak.3412DinoNovak.3412 USMember ✭✭

I have a page with complex constructor

public partial class SocialLoginPage : ContentPage
    {
        public SocialLoginPage(IOAuth2Service oAuth2Service)
        {
    ...
    }

I would like to add it to flyoutitem in shell

<FlyoutItem Route="home" Title="Home" Icon="ic_ig.png">
        <ShellContent ContentTemplate="{DataTemplate pages:SocialLoginPage}"/>
    </FlyoutItem>

But I am getting error that default constructir is missing for page.
How to resolve this issue?

Thanx,
D

Best Answer

  • DinoNovak.3412DinoNovak.3412 USMember ✭✭
    Accepted Answer

    Found the answer.

    name the Shell with x:Name="myshell"

    add FlyoutItem and do not set the shell content
    <FlyoutItem x:Name="fItem_1" Route="home" Title="Home" Icon="ic_ig.png">

    then from codebehind get the dependency service interface and add the shell item

    IOAuth2Service oAuth2Service = DependencyService.Get<IOAuth2Service>();
    
                ShellSection shell_section = new ShellSection
                {
                    Title = "Login - manual",
                };
    
                shell_section.Items.Add(new ShellContent() { Content = new SocialLoginPage(oAuth2Service) });
                fItem_1.Items.Add(shell_section);
    

Answers

  • DinoNovak.3412DinoNovak.3412 USMember ✭✭
    Accepted Answer

    Found the answer.

    name the Shell with x:Name="myshell"

    add FlyoutItem and do not set the shell content
    <FlyoutItem x:Name="fItem_1" Route="home" Title="Home" Icon="ic_ig.png">

    then from codebehind get the dependency service interface and add the shell item

    IOAuth2Service oAuth2Service = DependencyService.Get<IOAuth2Service>();
    
                ShellSection shell_section = new ShellSection
                {
                    Title = "Login - manual",
                };
    
                shell_section.Items.Add(new ShellContent() { Content = new SocialLoginPage(oAuth2Service) });
                fItem_1.Items.Add(shell_section);
    
  • jezhjezh Member, Xamarin Team Xamurai

    Congrats, and thank you for your support of xamarin.

Sign In or Register to comment.