簡體   English   中英

如何將 Xamarin Shell 應用程序的彈出項居中?

[英]How can I center the the flyout items of a Xamarin Shell application?

我想自定義我的 Xamarin Shell 應用程序的彈出窗口的外觀,以使其項目垂直居中。 Microsoft 文檔顯示了如何自定義浮出控件本身的某些方面,但這些設置無法操縱其外觀,因此我可以重新排列項目的顯示方式。

在此處輸入圖像描述

如果沒有彈出窗口 header,項目堆疊在彈出窗口的頂部,但我需要將它們垂直居中在彈出窗口本身的中間。

我的ShellItemRenderer.cs目前是空的,因為我不明白我需要做什么。 我目前有這些課程:

internal class CustomShellRenderer : ShellRenderer {
   public CustomShellRenderer(Context context) : base(context) { }

   protected override IShellTabLayoutAppearanceTracker CreateTabLayoutAppearanceTracker(ShellSection shellSection) {
      return new TabLayoutAppearanceTracker(this);                
   }

   protected override IShellItemRenderer CreateShellItemRenderer(ShellItem shellItem) {
      return new CustomShellItemRenderer(this);
   }
}

public class CustomShellItemRenderer :ShellItemRenderer {
   public CustomShellItemRenderer(IShellContext shellContext) : base(shellContext) { }
}

如您所見,它們是空的,因為我無法弄清楚需要進行的修改。

您可以使用Shell.ItemTemplate自定義彈出項:

<Shell.ItemTemplate>
    <DataTemplate>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="0.2*" />
                <ColumnDefinition Width="0.8*" />
            </Grid.ColumnDefinitions>
            <Image Source="{Binding Icon}"
                   Margin="5"
                   HeightRequest="45" />
            <Label Grid.Column="1"
                   Text="{Binding Title}"
                   FontAttributes="Italic"
                   HorizontalTextAlignment="Center"
                   VerticalTextAlignment="Center" /> 
        </Grid>
    </DataTemplate>
</Shell.ItemTemplate>

結果如下:

在此處輸入圖像描述

您還可以使用Shell.MenuItemTemplate自定義 MenuItem 外觀。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM