PSC.Xam.Controls.BindableRadioButton (component)

Nuget Package

BindableRadioButton for Xamarin Forms

This BindableRadioButton is the result of studying blog and forum posts. I'm using this component in more than 2000 views and 700 users. I think my component is stable.

Download it from NuGet.

For each platform (UWP, Android, iOS) you have to download the implementation. For question and support, visit your forum.

What's included?

A bindable radiobutton component.

XAML (example)

<?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:local="clr-namespace:BindingProject"
        xmlns:pscr="clr-namespace:PSC.Xam.Controls.BindableRadioButton;
                    assembly=PSC.Xam.Controls.BindableRadioButton"
        x:Class="BindingProject.MainPage">
    <ScrollView>
        <StackLayout>
            <Label Text="Check and Radio Group Demo" 
                  VerticalOptions="Center" 
                  HorizontalOptions="Center" />

            <pscr:BindableRadioGroup 
                  x:Name="MyRadioGroup" 
                  ItemsSource="{Binding Path=MyList.Values}" 
                  SelectedIndex="{Binding SelectedIndex}" 
                  VerticalOptions="Start" />

            <StackLayout Orientation="Horizontal">
                <Label Text="Selected Item is:" VerticalOptions="Center" 
                   HorizontalOptions="Center" />
                <Label x:Name="txtSelected" Text="" 
                   VerticalOptions="Center" 
                   HorizontalOptions="Center" />
            </StackLayout>
        </StackLayout>
    </ScrollView>
</ContentPage>


C# Code behind (example)

    public partial class MainPage : ContentPage
    {
        MainViewModel vm = null;

        public MainPage()
        {
            InitializeComponent();
            vm = new MainViewModel();
            this.BindingContext = vm;

            this.MyRadioGroup.CheckedChanged += MyRadioGroup_CheckedChanged;
            this.MyCheckGroup.CheckedChanged += MyCheckGroup_CheckedChanged;

            this.MyRadioGroup.SelectedIndex = 3;
            this.MyCheckGroup.Checkboxes[2].Checked = true;
        }

        private void MyCheckGroup_CheckedChanged(object sender, int e)
        {
            vm.SelectedItems = this.MyCheckGroup.SelectedItems;
        }

        void MyRadioGroup_CheckedChanged(object sender, int e)
        {
            var radio = sender as CustomRadioButton;
            if (radio == null || radio.Id == -1) return;
            this.txtSelected.Text = radio.Text;
            vm.SelectedIndex = this.MyRadioGroup.SelectedIndex;
        }
    }

C# MainViewModel

    public class MainViewModel : BaseViewModel
    {
        public MainViewModel() {
            myList = new Dictionary<int, string>();
            selectedIndex = -1;
            LoadData();
        }

        private void LoadData()
        {
            for (int i = 0; i < 5; i++)
            {
                MyList.Add(i, "Item " + i);
            }
        }

        private Dictionary<int, string> myList;
        public Dictionary<int, string> MyList
        {
            get { return myList; }
            set {
                myList = value;
                OnPropertyChanged("MyList");
            }
        }

        private int selectedIndex;
        public int SelectedIndex
        {
            get { return selectedIndex; }
            set {
                if (value == selectedIndex) return;
                selectedIndex = value;
                OnPropertyChanged("SelectedIndex");
            }
        }
    }

Screenshot

Android

iOS

UWP

Advertsing

125X125_06

Planet Xamarin

Planet Xamarin

Calendar

<<  October 2017  >>
MonTueWedThuFriSatSun
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

View posts in large calendar

Month List