Я хочу знать, как добавить повторно используемое плавающее меню на все страницы приложения xamarin?
Есть ли у нас возможность создать макет главной страницы и добавить частичные представления в xamarin?
Например, в шаблоне ниже я хочу повторить следующий раздел stacklayout на всех страницах.
На странице у меня есть следующие
<ContentPage.Content>
<ScrollView>
<StackLayout BackgroundColor = "MediumPurple" VerticalOptions = "FillAndExpand" HorizontalOptions = "FillAndExpand" >
<StackLayout Orientation = "Horizontal" HorizontalOptions = "FillAndExpand" BackgroundColor = "White">
<StackLayout Orientation = "Vertical" HorizontalOptions = "FillAndExpand" >
<Button Text = "All" Clicked = "PromoAll_Clicked" BackgroundColor = "Orange" />
</StackLayout>
</StackLayout>
<Label Text = "Upcoming Events" VerticalTextAlignment = "Center" FontSize = "Large" TextColor = "White" HorizontalOptions = "Center" />
<ListView x:Name = "PromolistView" ItemTapped = "promoOnItemSelected" RowHeight = "55" BackgroundColor = "MediumPurple" HasUnevenRows = "True" HorizontalOptions = "FillAndExpand" VerticalOptions = "FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
....
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
// this area needs to be repeated every page
<StackLayout Orientation = "Horizontal" VerticalOptions = "End">
<Button Text = "A" FontAttributes = "Bold" BackgroundColor = "MediumSlateBlue" BorderRadius = "50" TextColor = "White"></Button>
<Button Text = "B" FontAttributes = "Bold" BackgroundColor = "MediumSlateBlue" TextColor = "White"></Button>
</StackLayout>
//end of the floating menu
</StackLayout>
</ScrollView>
</ContentPage.Content>





В Xamarin.Forms Шаблон управления и Вид в некоторой степени аналогичны макету главной страницы и частичному представлению в ASP.NET. В качестве быстрого примера:
App.xaml
<?xml version = "1.0" encoding = "utf-8"?>
<Application xmlns = "http://xamarin.com/schemas/2014/forms" xmlns:x = "http://schemas.microsoft.com/winfx/2009/xaml" x:Class = "TemplateExample.App">
<Application.Resources>
<ResourceDictionary>
<ControlTemplate x:Key = "HeaderTemplate">
<Grid Padding = "0,40,0,0">
<Grid.RowDefinitions>
<RowDefinition Height = "Auto" />
<RowDefinition Height = "*" />
</Grid.RowDefinitions>
<BoxView BackgroundColor = "Gray" Grid.Row = "0" HeightRequest = "50" />
<Label Grid.Row = "0" Text = "This is the header" TextColor = "White" HorizontalOptions = "Center" VerticalOptions = "Center" />
<ContentPresenter Grid.Row = "1" />
</Grid>
</ControlTemplate>
</ResourceDictionary>
</Application.Resources>
</Application>
TemplatedPage.xaml
<?xml version = "1.0" encoding = "UTF-8"?>
<ContentPage xmlns = "http://xamarin.com/schemas/2014/forms" xmlns:x = "http://schemas.microsoft.com/winfx/2009/xaml" x:Class = "TemplateExample.Views.TemplatedPage">
<ContentView ControlTemplate = "{StaticResource HeaderTemplate}">
<StackLayout Orientation = "Vertical" HorizontalOptions = "Center" VerticalOptions = "CenterAndExpand">
<Label Text = "This is the content" />
</StackLayout>
</ContentView>
</ContentPage>
Визуализированный шаблон и просмотр
Я обновил свой ответ, добавив пример кода и снимок экрана.
у вас есть пример использования этих ресурсов?