Xamarin.Forms三

news/2024/7/1 10:21:52

Page主要分为ContentPage、MasterDetailPage、NavigationPage、TabbedPage和CarouselPage。
ContentPage
一个单独的页面,可以放一个或多个控件,属于page里面是最底层的元素。

 1     /// <summary>
 2     /// ContentPage
 3     /// </summary>
 4     public class TestContentPage : ContentPage
 5     {
 6         public TestContentPage()
 7         {
 8             //隐藏上方的工具栏
 9             NavigationPage.SetHasNavigationBar(this, false);
10             //该page绑定的Model类
11             this.BindingContext = new TestModel();
12             //该Page的显示内容
13             this.Content = TestStackLayout();
14             //该Page工具栏的Title显示
15             this.Title = "Test页";
16             //工具栏的工具
17             ToolbarItem textToolbarItem1 = new ToolbarItem("Test", "test.jpg", () =>
18             {
19                 DisplayAlert("工具", "you click this toolbar", "OK");
20             }, 0, 0);
21 
22             ToolbarItem textToolbarItem2 = new ToolbarItem("Test", "test.jpg", () =>
23             {
24             }, 0, 0);
25             //工具的点击事件绑定
26             textToolbarItem2.SetBinding(ToolbarItem.CommandProperty, "SubmitCommand");
27 
28             this.ToolbarItems.Add(textToolbarItem1);
29             this.ToolbarItems.Add(textToolbarItem2);
30             //背景图片
31             this.BackgroundImage = "test.jpg";
32             //背景颜色
33             this.BackgroundColor = Color.Blue;
34         }
35 
36         /// <summary>
37         /// stacklayout布局
38         /// </summary>
39         /// <returns></returns>
40         public StackLayout TestStackLayout()
41         {
42             var textName = new Label
43             {
44             };
45             textName.SetBinding(Label.TextProperty, "TestName");
46 
47             var textImage = new Image
48             {
49             };
50             textImage.SetBinding(Image.SourceProperty, "ImageSource");
51 
52             var testViewCellSL = new StackLayout
53             {
54                 Orientation = StackOrientation.Horizontal,
55                 Padding = new Thickness(5, 10, 20, 30),
56                 Spacing = 10,
57                 Children =
58                 {
59                     textImage,
60                     textName,
61                 },
62             };
63             return testViewCellSL;
64         }
65     }
View Code

MasterDetailPage
一个收缩页,一个详细显示信息页,这个研究的不太多,只是做个一个例子,感觉还不错。

可以参考:https://github.com/xamarin/xamarin-forms-samples/blob/master/FormsGallery/FormsGallery/FormsGallery/MasterDetailPageDemoPage.cs。


NavigationPage
一个page的堆栈,用做主界面的,打开一个新的page,往堆栈中压一个page,退出一个page,则从堆
栈中将最上层的page,即显示的page抛出去。

 1 var pushBtn = new Button
 2             {
 3                 Text = "Push",
 4             };
 5             pushBtn.Clicked += (sender, e) =>
 6                 {
 7                     //压入一个页面
 8                     this.Navigation.PushAsync(new TestContentPage());
 9                 };
10 
11             var popBtn = new Button
12             {
13                 Text = "Pop",
14             };
15             popBtn.Clicked += (sender, e) =>
16             {
17                 //抛出当前页面
18                 this.Navigation.PopAsync();
19             };
View Code

TabbedPage
一个Tab一个Page,不过我感觉这个不太好使,用了一段时间就放弃了,Tab的位置是固定的,不能设置。

 1     /// <summary>
 2     /// TabbedPage
 3     /// </summary>
 4     public class TestTabbedPage : TabbedPage
 5     {
 6         public TestTabbedPage()
 7         {
 8              this.Children.Add(new TestContentPage(){Title = "First"});
 9              this.Children.Add(new TestContentPage(){Title = "Second"});
10              this.Children.Add(new TestContentPage() { Title = "Third" });
11 
12              //刚进入显示的tab页
13              this.SelectedItem = Children.Where(x=>x.Title == "Second").FirstOrDefault();
14         }
15     }
View Code

CarouselPage
多个滑动Page,这个还是可以的。属性与TabbedPage基本一致。

页面我都尝试过,不过最后还是主要放在了ContentPage和CarouselPage上。


官方网址:http://developer.xamarin.com/guides/cross-platform/xamarin-forms/controls/pages/

转载于:https://www.cnblogs.com/shadow-fei/p/4174277.html


http://www.niftyadmin.cn/n/711405.html

相关文章

超级计算机看未来天气,广东气候要变?超级计算机:未来10天或滴雨不下,比西北还干燥...

对于我国来说&#xff0c;这段时间南方的很多地方可以说是干燥得吓人&#xff0c;即便是10月下旬有几场喜雨到来&#xff0c;我国江西浙江福建等地的气象干旱也并未能完全解除。而从中国气象局国家气候中心的监测数据上看&#xff0c;过去10天(10月20日-10月29日)我国东部、南部…

CentOS安装JAVA后JAVA版本不对的问题

今天用CentOS安装JDK&#xff0c;发觉在安装完成后&#xff0c;输入java命令来验证是否安装成功时&#xff0c;出现 Usage: gij [OPTION] ... CLASS [ARGS] ... to invoke CLASS.main, or gij -jar [OPTION] ... JARFILE [ARGS] ... to execute a jar …

MyBatis-Plus——逆向工程之AutoGenerator代码生成器

1.案例详解 首先在Navicat中创建一张表。 创建一个SpringBoot项目&#xff0c;在pom文件中添加相关依赖。 大部分依赖我们都是见过的&#xff0c;因为这里需要使用MP框架中的逆向工程生成代码&#xff0c;所以还需要一个模板引擎依赖。 <dependency><groupId>org.s…

黑马程序员—11-oc初认识

------- android培训、java培训、期待与您交流&#xff01; ---------- 一、 OC简介 C语言的基础上&#xff0c;增加了一层最小的面向对象语法 完全兼容C语言 可以在OC代码中混入C语言代码&#xff0c;甚至是C代码 可以使用OC开发Mac OS X平台和iOS平台的应用程序…

创建dynamics CRM client-side (七) - 用JS 来控制Auto-Save

在我们的system setting里面&#xff0c; 我们可以设置打开/关闭 auto save的功能。 我们可以用js来控制auto-save this.formOnSave function (executionContext) {var eventArgs executionContext.getEventArgs();if (eventArgs.getSaveMode() 70 || eventArgs.getSaveMode…

计算机硬件系统方案表,基于EDA技术的计算机硬件系统设计方案

1引言随着计算机技术的迅速发展&#xff0c;计算机系统中使用的硬件部件基本上都采用大规模和超大规模集成电路&#xff0c;这些电路的设计、验证和测试必须使用先进的工具软件&#xff0c;使硬件设计逐渐趋于软件化&#xff0c;加快硬件设计和调试的速度&#xff0c;计算机硬件…

cocos2d JS-(JavaScript) 静态方法的例子

1 function User(name, age) {2 this.name name;3 this.age age;4 }5 var user new User(angela,26);6 7 User.cloneUser function (user) {//静态方法8 return new User(user.name, user.age);//创建…

CentOS下date命令 - 显示和设置系统日期与时间

显示系统日期 要显示系统日期,只要输入: $ date Thu Dec 5 22:55:41 WIB 2013 格式化显示日期 日期有很多格式。如果你不喜欢默认的格式&#xff0c;你可以换一种格式。你可能会想"为什么我需要改变格式? 默认的输出对我足够了。" 是的&#xff0c;你说的对&#xf…