![](/img/trans.png)
[英]How can I center the the flyout items of a Xamarin Shell application?
[英]Dynamic items in Shell flyout, without losing static items?
在使用 MAUI Shell 类(使用 XAML)时,我正在努力寻找一种在不丢失现有静态项的情况下添加动态弹出项的方法。 我曾尝试使用Shell.FlyoutContentTemplate
,但这似乎用我的模板替换了弹出窗口的全部内容,并完全隐藏了我想要保留的静态项目。 有谁知道如何成功地做到这一点?
<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>
您可以通过单击按钮或其他方式在代码中添加某个ShellContent
。
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.