Xamarin. Типы страниц Page - ContentPage, TabbedPage, NavigationPage, MasterDetailPage, CarouselPage
Это видео - часть бесплатного обучения в Xamarin University. Чтобы просмотреть весь курс, посетите https://university.xamarin.com/.
Pages
Рассмотрим страницы - Page, которые создают некую иерархию.ContentPage
Представляет собой обычную страницу с данными. Имеет свойство Content, которое может содержать в себе элементы UI.Пример создания ContentPage c одним элементом UI:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public App(){ | |
MainPage = new ContentPage{ | |
Content = new Label{ | |
Text = "Hello, Forms!", | |
BackgroundColor = Color.Blue, | |
}, | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public App () | |
{ | |
// The root page of your application | |
var layout = new StackLayout | |
{ | |
VerticalOptions = LayoutOptions.Center, | |
Children = { | |
new Label { | |
HorizontalTextAlignment = TextAlignment.Center, | |
Text = "Welcome to Xamarin Forms!" | |
} | |
} | |
}; | |
MainPage = new ContentPage | |
{ | |
Content = layout | |
}; | |
Button button = new Button | |
{ | |
Text = "Click Me" | |
}; | |
button.Clicked += async (s, e) => { | |
await MainPage.DisplayAlert("Alert", "You clicked me", "OK"); | |
}; | |
layout.Children.Add(button); | |
} |
MasterDetailPage
Представляет собой станицу навигации с переключением между другими станицами. Имеет общий заголовок и ссылки с названиями на другие страницы.Пример создания MasterDetailPage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public App(){ | |
MasterNav = new NavigationPage(new CustomerListPAge()){ | |
Title = "Customers", | |
}; | |
DetailNav = new NavigationPage(new NoCustomerDetailPage()); | |
MainPage = new MasterDetailPage{ | |
Master = MasterNav, | |
Detail = DetailNav, | |
}; | |
} | |
public static void NavigateToCustomer(Customer c){ | |
MasterDetail Detail = new NavigationPage(new CustomerDetailsPage(c)); | |
MasterDetail.IsPresented = true; | |
} |
MasterDetailPage - официальная документация (на английском)
NavigationPage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public App(){ | |
MainPage = new NavigationPage(new ColorListPage(ColorLoader.GetColors())); | |
} |
TabbedPage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public App(){ | |
var tabbedPage = new TabbedPage(); | |
tabbedPage.Children.Add(new ColorDetailPage(Color.Red)); | |
tabbedPage.Children.Add(new ColorDetailPage(Color.Green)); | |
tabbedPage.Children.Add(new ColorDetailPage(Color.Blue)); | |
tabbedPage.Children.Add(new ColorDetailPage(Color.Pink)); | |
tabbedPage.Children.Add(new ColorDetailPage(Color.Teal)); | |
tabbedPage.Children.Add(new ColorDetailPage(Color.Lime)); | |
MainPage = tabbedPage; | |
} |
CarouselPage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public App() { | |
var carouselPage = new CarouselPage(); | |
carouselPage.Children.Add(new ColorDetailPage(Color.Red)); | |
carouselPage.Children.Add(new ColorDetailPage(Color.Green)); | |
carouselPage.Children.Add(new ColorDetailPage(Color.Blue)); | |
carouselPage.Children.Add(new ColorDetailPage(Color.Pink)); | |
carouselPage.Children.Add(new ColorDetailPage(Color.Teal)); | |
carouselPage.Children.Add(new ColorDetailPage(Color.Lime)); | |
MainPage = carouselPage; | |
} |
Комментарии
Отправить комментарий