Как создать слайдер с помощью Xamarin.Forms? Это запекается или что-то обычное?
Как создать меню ящика/слайдера с помощью Xamarin.Forms?
Ответ 1
Вы создаете новый класс, который содержит все определения как для Master, то есть для меню, так и для Detail, то есть для главной страницы. Я знаю, это звучит обратно к фронту, но, к примеру..
using System;
using Xamarin.Forms;
namespace testXamForms
{
public class HomePage : MasterDetailPage
{
public HomePage()
{
// Set up the Master, i.e. the Menu
Label header = new Label
{
Text = "MENU",
Font = Font.BoldSystemFontOfSize(20),
HorizontalOptions = LayoutOptions.Center
};
// create an array of the Page names
string[] myPageNames = {
"Main",
"Page 2",
"Page 3",
};
// Create ListView for the Master page.
ListView listView = new ListView
{
ItemsSource = myPageNames,
};
// The Master page is actually the Menu page for us
this.Master = new ContentPage
{
Title = "The Title is required.",
Content = new StackLayout
{
Children =
{
header,
listView
},
}
};
// Define a selected handler for the ListView contained in the Master (ie Menu) Page.
listView.ItemSelected += (sender, args) =>
{
// Set the BindingContext of the detail page.
this.Detail.BindingContext = args.SelectedItem;
Console.WriteLine("The args.SelectedItem is
{0}",args.SelectedItem);
// This is where you would put your "go to one of the selected pages"
// Show the detail page.
this.IsPresented = false;
};
// Set up the Detail, i.e the Home or Main page.
Label myHomeHeader = new Label
{
Text = "Home Page",
HorizontalOptions = LayoutOptions.Center
};
string[] homePageItems = { "Alpha", "Beta", "Gamma" };
ListView myHomeView = new ListView {
ItemsSource = homePageItems,
};
var myHomePage = new ContentPage();
myHomePage.Content = new StackLayout
{
Children =
{
myHomeHeader,
myHomeView
} ,
};
this.Detail = myHomePage;
}
}
}
Ответ 2
Он встроен: MasterDetailPage
. Вы должны установить свойства Detail
и Master
для всех типов страниц. Я нашел Hansleman.Forms, чтобы быть достаточно просвещенным.
Ответ 3
Мой минимальный пример (как указано здесь) выглядит следующим образом:
public class App
{
static MasterDetailPage MDPage;
public static Page GetMainPage()
{
return MDPage = new MasterDetailPage {
Master = new ContentPage {
Title = "Master",
BackgroundColor = Color.Silver,
Icon = Device.OS == TargetPlatform.iOS ? "menu.png" : null,
Content = new StackLayout {
Padding = new Thickness(5, 50),
Children = { Link("A"), Link("B"), Link("C") }
},
},
Detail = new NavigationPage(new ContentPage {
Title = "A",
Content = new Label { Text = "A" }
}),
};
}
static Button Link(string name)
{
var button = new Button {
Text = name,
BackgroundColor = Color.FromRgb(0.9, 0.9, 0.9)
};
button.Clicked += delegate {
MDPage.Detail = new NavigationPage(new ContentPage {
Title = name,
Content = new Label { Text = name }
});
MDPage.IsPresented = false;
};
return button;
}
}
Примерное решение размещено в GitHub.
В iOS результат выглядит следующим образом (влево: меню открыто, справа: после нажатия на "B" ):
Обратите внимание, что вам нужно добавить значок меню в качестве ресурса в свой проект iOS.
Ответ 4
Если вы ищете простой пример MasterDetailPage, пожалуйста, взгляните на мой образец репо на GitHub. Очень красивый пример также представлен здесь
Ответ 5
Slideoverkit - отличный плагин для Xamarin Forms. Существует github, чтобы просмотреть бесплатные образцы, и вы можете найти документацию об этом .