5.Xamarin.Forms里按钮的实现
来源:互联网 发布:xbox one 移动网络 dns 编辑:程序博客网 时间:2024/09/21 09:28
其实Xamarin.Forms中的按钮的用发和WPF的几乎一样。
先看看这个吧,创建一个按钮并添加点击事件。
class aaa:ContentPage { StackLayout a = new StackLayout(); public aaa() { Button b = new Button { Text = "button" }; b.Clicked += B_Clicked; Content = new StackLayout { Children = { b, new ScrollView { VerticalOptions=LayoutOptions.FillAndExpand, Content=a } } }; } private void B_Clicked(object sender, EventArgs e) { a.Children.Add(new Label { Text = "Clicked at" + DateTime.Now.ToString("T") }); } }
最终的效果
当然也可以在代码中使用Lambda表达式。如下:
class aaa:ContentPage { StackLayout a = new StackLayout(); public aaa() { Button b = new Button { Text = "button" }; b.Clicked += (s, e) => { a.Children.Add(new Label { Text = "Clicked at" + DateTime.Now.ToString("T") }); }; Content = new StackLayout { Children = { b, new ScrollView { VerticalOptions=LayoutOptions.FillAndExpand, Content=a } } }; } }
以下是Button可以设置的属性:
FontFamily FontSize FontAttributes TextColor BorderColor BorderWidth BorderRadius Image
下面展示的是两个按钮如何使用同一个事件,做不同的事:
class aaa:ContentPage { StackLayout a = new StackLayout(); Button b = new Button { Text = "Add", HorizontalOptions = LayoutOptions.CenterAndExpand }; Button c = new Button { Text = "Remove", HorizontalOptions = LayoutOptions.CenterAndExpand }; public aaa() { b.Clicked += B_Clicked; c.Clicked += B_Clicked; Content = new StackLayout { Children = { new StackLayout { Orientation=StackOrientation.Horizontal, Children= { b,c } }, new ScrollView { VerticalOptions=LayoutOptions.FillAndExpand, Content=a } } }; } private void B_Clicked(object sender, EventArgs e) { Button button = (Button)sender; if (button == b) { a.Children.Add(new Label { Text = "Clicked at" + DateTime.Now.ToString("T") }); } else { a.Children.RemoveAt(0); } c.IsEnabled = a.Children.Count > 0; } }
1 0
- 5.Xamarin.Forms里按钮的实现
- 2.Xamarin.Forms里的文本控制
- xamarin IOS对xamarin.forms的Tabbedpage的renderer实现
- xamarin.forms中自定义控件的android实现
- Xamarin.Forms教程开发Xamarin.Forms应用程序需要的工具
- Xamarin.Forms 的一点体会
- Xamarin.forms Image实现圆形图片
- xamarin.forms Geolocator Plugin 地理位置的获取
- xamarin.forms 拍照和视频的操作
- Xamarin.Forms 获取设备的ip地址
- Xamarin.Forms的ActivityIndicator和ProgressBar比较
- Xamarin.Forms特殊的视图BoxView
- Xamarin.Forms支持的地图显示类型
- Xamarin.Forms XAML控件的公共属性
- Xamarin.Forms的滚动视图ScrollView
- Xamarin.Forms的相对布局RelativeLayout
- Xamarin.Forms使用XLabs.Forms时MainActivity的继承问题
- Xamarin Forms-通用事件绑定(Event Binding)的实现
- java复制大文件
- 如何判断一个数是不是2的n次幂
- PHP+MYSQL数据库查询显示
- c++类静态成员详解
- PL语句块中各种循环
- 5.Xamarin.Forms里按钮的实现
- 网站国际化代码-多语言
- 解决虚拟机提示VMwareWorkstationcannotconnecttothevirtualmachine的问题
- Service的使用
- MongoDB基本使用
- sitemesh教程-页面装饰技术原理及应用
- 火云开发课堂 - 《Shader从入门到精通》系列 第二十五节:在Shader中实现3DALPHA混合与测试
- 分享图片到朋友圈
- 处理get中文乱码