Xamarin-Forms-Labs RadioButton控件使用

今天以RadioButton控件为例,介绍下Xamarin-Forms-Labs如何在我们项目中使用

XLabs is a open source project that aims to provide a powerful and
cross platform set of services and controls tailored to work with
Xamarin and Xamarin Forms. XLabs是一个开源的项目,为Xamarin提供了跨平台的服务和控件。

XLabs的GitHub地址为https://github.com/forrest23/Xamarin-Forms-Labs

  1. 将项目download到本地,用Xamarin Studio打开项目文件XLabs.sln,然后编译,编译成功后在build文件中会有很多dll文件。在你项目中新建一个文件夹,将dll拷贝过去。然后在你的主项目、IOS项目、安卓项目中分别添加这几个dll的引用。
    clipboard.png

  2. 新建一个Forms,类型选择ContentPage Xaml
    clipboard.png

  3. 在xaml布局文件中添加以下代码来添加一个RadioButtonGroup控件
    <?xml version="1.0" encoding="UTF-8"?>

       <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
       xmlns:control="clr-namespace:XLabs.Forms.Controls;assembly=XLabs.Forms"
       x:Class="PocketDoctor.PatientSearch">
           <ContentPage.Content>
                <StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand">
                    <control:BindableRadioGroup x:Name="ansPicker" SelectedIndex="{Binding ItemSelected}" TextColor="#70c7da" Orientation="Horizontal" HorizontalOptions="FillAndExpand"/>
                    </StackLayout>
           </ContentPage.Content>
       </ContentPage> 

    注意:只有添加了xmlns:control="clr-namespace:XLabs.Forms.Controls;assembly=XLabs.Forms" 这句话才能使用XLabs.Forms中的控件。

  4. 在.xaml.cs文件中添加以下代码给RadioButtonGroup的ItemsSource赋值:

    public PatientSearch ()

           {
               InitializeComponent ();
               this.Title = "搜索患者" ;
               ansPicker.ItemsSource = new[]
               {
                   "姓名",
                   "住院号",
                   "床位号",
               };
               ansPicker.Spacing=0;
               ansPicker.Items [0].WidthRequest = 80; 
               ansPicker.Items [1].WidthRequest = 100;
               ansPicker.Items [2].WidthRequest = 100;
               ansPicker.CheckedChanged += ansPicker_CheckedChanged;
               ansPicker.Items[0].Checked = true;

    }

  5. 这样Xamarin-Forms-Labs RadioButton控件使用就介绍完毕。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值