简体   繁体   中英

Dynamic items in Shell flyout, without losing static items?

While using the MAUI Shell class (with XAML), I am struggling to find a way to add dynamic flyout items without losing existing static items. I have tried using a Shell.FlyoutContentTemplate , but that seems to replace the entire contents of the flyout with my template, and completely hides the static items that I want to keep. Does anyone know how to do this successfully?

<Shell
    x:Class="Frostgrave_Helper.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:Frostgrave_Helper"
    Title="Frostgrave Warbands"
    FlyoutBackground="{AppThemeBinding Light={StaticResource IceBrush}, Dark={StaticResource IceBrushDark}}">

    <Shell.FlyoutHeaderTemplate>
        <DataTemplate>
            <Grid BackgroundColor="#00000000"
                  HeightRequest="200">
                <Image Aspect="AspectFit"
                       Source="frostgrave.png" />
            </Grid>
        </DataTemplate>
    </Shell.FlyoutHeaderTemplate>
    
    <Shell.FlyoutContentTemplate>
        <DataTemplate>
            <StackLayout>
                <ListView x:Name="MenuItemsListView"
                          SeparatorVisibility="None"
                          HasUnevenRows="true"
                          ItemsSource="{Binding WarbandNames}">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <StackLayout Padding="15,10"
                                             HorizontalOptions="FillAndExpand">
                                    <Label VerticalOptions="FillAndExpand"
                                           VerticalTextAlignment="Center"
                                           Text="{Binding}"
                                           TextColor="Black"
                                           FontSize="20"/>
                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>
        </DataTemplate>
    </Shell.FlyoutContentTemplate>

    <ShellContent Title="New warband..."
                Icon="plus_solid.png"
                ContentTemplate="{DataTemplate local:views.NewWarbandPage}" />

    <ShellContent Title="About"
                Icon="circle_info_solid.png"
                ContentTemplate="{DataTemplate local:About}" />

    <Shell.FlyoutFooterTemplate>
        <DataTemplate>
            <StackLayout>
                <Label Text="Tetra Software Consultancy"
                       TextColor="Black"
                       HorizontalOptions="Center" />
            </StackLayout>
        </DataTemplate>
    </Shell.FlyoutFooterTemplate>
</Shell>

You can add a certain ShellContent in code behind with a button click or something else .

Sample code

private void Button_Clicked(object sender, EventArgs e)
{
    ShellContent content = new ShellContent();
    content.Title = "test";
    content.FlyoutIcon = "dotnet_bot.svg";
    content.Content = new MainPage();

    AppShell.Current.Items.Add(content);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM