Shell - Add page with constructor argument

kyletraynor.4279kyletraynor.4279 USMember ✭✭
edited February 5 in Xamarin.Forms

I'm trying to use the new Shell for Forms 4.0

I have some pages that I would have added in the past like this new GenericPage("link");

Is there a way I can do that with Shell in xaml?

This is what I have now:

    <ShellItem x:Name="RepSpotlight">
        <ShellSection Title="Stats" Icon="tab_feed.png">
            <ShellContent ContentTemplate="{DataTemplate local:Spotlight.StatsPage}" />
        </ShellSection>
        <ShellSection Title="Upcoming" Icon="tab_about.png">
            <ShellContent ContentTemplate="{DataTemplate local:Spotlight.UpcomingPage}"  />
        </ShellSection>
        <ShellSection Title="By Month" Icon="tab_about.png">
            <ShellContent ContentTemplate="{DataTemplate local:Spotlight.ByMonthPage}" />
        </ShellSection>
    </ShellItem>

I'd love to be able to do something like this:

<ShellSection Title="Stats" Icon="tab_feed.png">
<ShellContent ContentTemplate="{DataTemplate local:Spotlight.GenericPage("stats")}" />
</ShellSection>

Or maybe something like:

<ShellSection Title="Stats" Icon="tab_feed.png">
<ShellContent ContentTemplate="{DataTemplate local:Spotlight.GenericPage}" parameter="stats" />
</ShellSection>

Is anything similar to this possible? How would I go about doing it?

Thanks!

Answers

  • Tracy320Tracy320 Member ✭✭

    Have you got th solution?

  • kyletraynor.4279kyletraynor.4279 USMember ✭✭

    Unfortunately not =(

  • jmdapozzojmdapozzo Member

    You can use a parameter in the creator

            public RaceEventCollectionPage(string filter)
            {
                string Filter = filter;
                InitializeComponent();
            }
    

    then pass an argument from xaml

        <ShellItem Title="{x:Static res:Strings.RaceEventCollectionCaption}" Icon="Race.png" FlyoutIcon="Race.png">
            <ShellSection>
                <ShellContent  Title="{x:Static res:Strings.RaceEventCollectionUpcomingEventsCaption}" BindingContext="{Binding Source={x:Reference appShell}, Path=BindingContext}">
                    <ShellContent.ContentTemplate>
                        <DataTemplate>
                            <views:RaceEventCollectionPage>
                                <x:Arguments>
                                    <x:String>UpcomingEvents</x:String>
                                </x:Arguments>
                            </views:RaceEventCollectionPage>
                        </DataTemplate>
                    </ShellContent.ContentTemplate>
                </ShellContent>
    
                <ShellContent Title="{x:Static res:Strings.RaceEventCollectionPastEventsCaption}" BindingContext="{Binding Source={x:Reference appShell}, Path=BindingContext}">
                    <ShellContent.ContentTemplate>
                        <DataTemplate>
                            <views:RaceEventCollectionPage>
                                <x:Arguments>
                                    <x:String>PastEvents</x:String>
                                </x:Arguments>
                            </views:RaceEventCollectionPage>
                        </DataTemplate>
                    </ShellContent.ContentTemplate>
                </ShellContent>
                <ShellContent Title="{x:Static res:Strings.RaceEventCollectionAllEventsCaption}" BindingContext="{Binding Source={x:Reference appShell}, Path=BindingContext}">
                    <ShellContent.ContentTemplate>
                        <DataTemplate>
                            <views:RaceEventCollectionPage>
                                <x:Arguments>
                                    <x:String>AllEvents</x:String>
                                </x:Arguments>
                            </views:RaceEventCollectionPage>
                        </DataTemplate>
                    </ShellContent.ContentTemplate>
                </ShellContent>
            </ShellSection>
        </ShellItem>
    
Sign In or Register to comment.