Xamarin forms labs RadioButton control

Time:2022-5-5

Today, take RadioButton control as an example to introduce how xamarin forms labs is used in our project

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 is an open source project that provides cross platform services and controls for xamarin.

The GitHub address of xlabs is https://github.com/forrest23/Xamarin-Forms-Labs

  1. Download the project locally and use xamarin studio to open the project file xlabs SLN, and then compile. After successful compilation, there will be many DLL files in the build file. Create a new folder in your project and copy the DLL. Then add references to these DLLs in your main project, IOS project and Android project respectively.
    Xamarin forms labs RadioButton control

  2. Create a new forms and select contentpage XAML as the type
    Xamarin forms labs RadioButton control

  3. Add the following code to the XAML layout file to add a radiobuttongroup control
    <?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> 

    Note: xlabs can only be used when xmlns: control = “CLR namespace: xlabs. Forms. Controls; assembly = xlabs. Forms” is added Controls in forms.

  4. Yes xaml. CS file, add the following code to assign a value to itemssource of radiobuttongroup:

    public PatientSearch ()

    {
               InitializeComponent ();
               this. Title = "search for patients";
               ansPicker.ItemsSource = new[]
               {
                   "Name",
                   "Inpatient number",
                   "Bed number",
               };
               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. This completes the introduction to the use of the xamarin forms labs RadioButton control.