简体   繁体   English

Shell弹出中的动态项目,而不会丢失静态项目?

[英]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.在使用 MAUI Shell 类(使用 XAML)时,我正在努力寻找一种在不丢失现有静态项的情况下添加动态弹出项的方法。 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.我曾尝试使用Shell.FlyoutContentTemplate ,但这似乎用我的模板替换了弹出窗口的全部内容,并完全隐藏了我想要保留的静态项目。 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 .您可以通过单击按钮或其他方式在代码中添加某个ShellContent

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 Xamarin Shell 应用程序的弹出项居中? - How can I center the the flyout items of a Xamarin Shell application? Shell 弹出菜单始终未显示所有菜单项 .NET MAUI Windows - Shell Flyout Menu not showing all the Menu Items All the time in .NET MAUI Windows 混合动态和静态XAML菜单项 - Mixing dynamic and static XAML menu items RibbonDropDown丢失物品 - RibbonDropDown losing items 从列表中删除项目而不丢失原始参考-逻辑问题 - Removing items from a List without losing original reference - logic issue 如何对 IEnumerable 进行分块<T> ,在失败的情况下不会丢失/丢弃物品? - How to chunkify an IEnumerable<T>, without losing/discarding items in case of failure? 从列表中逐个获取项目而不会丢失旧值 - Take items from list one by one without losing the old value 如何从横向菜单上的弹出项进行推送 - How to make a push from flyout items on lateral menu 当前几个 JSON 项目具有非十进制值时,将动态 JSON 反序列化为 DataTable 会丢失小数 - Deserialization of dynamic JSON to a DataTable is losing decimals when first few JSON items have non-decimal values 静态列表中的项目 <Item> () - Items in static List<Item>()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM