NavigationPage Bar Translucency unter iOS
Diese plattformspezifische iOS-Plattform wird verwendet, um die Transparenz der Navigationsleiste in einem NavigationPage
zu ändern und 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 über C# mit der Fluent-API 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 NavigationPage.EnableTranslucentNavigationBar
-Methode im Xamarin.Forms.PlatformConfiguration.iOSSpecific
Namespace wird verwendet, um die Navigationsleiste lichtdurchlässig zu machen. Darüber hinaus verfügt die NavigationPage
-Klasse im Xamarin.Forms.PlatformConfiguration.iOSSpecific
Namespace auch über eine DisableTranslucentNavigationBar
-Methode, die die Navigationsleiste in ihren Standardzustand zurückgibt, und eine SetIsNavigationBarTranslucent
Methode, die verwendet werden kann, um die Transparenz der Navigationsleiste durch Aufrufen der IsNavigationBarTranslucent
-Methode umzuschalten:
(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: