![](/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.