Share via


NavigationPage Bar Translucency unter iOS

Diese plattformspezifische iOS-Plattform wird verwendet, um die Transparenz der Navigationsleiste in einem , NavigationPageund wird in XAML verwendet, indem die NavigationPage.IsNavigationBarTranslucent angefügte Eigenschaft auf einen boolean Wert festgelegt wird:

<NavigationPage ...
                xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
                BackgroundColor="Blue"
                ios:NavigationPage.IsNavigationBarTranslucent="true">
  ...
</NavigationPage>

Alternativ kann sie mit der Fluent-API von C# genutzt werden:

using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
...

(App.Current.MainPage as Xamarin.Forms.NavigationPage).BackgroundColor = Color.Blue;
(App.Current.MainPage as Xamarin.Forms.NavigationPage).On<iOS>().EnableTranslucentNavigationBar();

Die NavigationPage.On<iOS> Methode gibt an, dass diese plattformspezifische Nur unter iOS ausgeführt wird. Die Methode NavigationPage.EnableTranslucentNavigationBar im Xamarin.Forms.PlatformConfiguration.iOSSpecific-Namespace wird verwendet, um die Navigationsleiste transparent zu machen. Außerdem verfügt die Klasse NavigationPage im Xamarin.Forms.PlatformConfiguration.iOSSpecific-Namespace über eine DisableTranslucentNavigationBar-Methode, die den Standardzustand der Navigationsleiste wiederherstellt, und eine SetIsNavigationBarTranslucent-Methode, mit der Sie die Transparenz der Navigationsleiste durch den Aufruf der IsNavigationBarTranslucent-Methode umschalten können:

(App.Current.MainPage as Xamarin.Forms.NavigationPage)
  .On<iOS>()
  .SetIsNavigationBarTranslucent(!(App.Current.MainPage as Xamarin.Forms.NavigationPage).On<iOS>().IsNavigationBarTranslucent());

Das Ergebnis ist, dass die Transparenz der Navigationsleiste geändert werden kann:

Transluzente Navigationsleiste plattformspezifisch