Search code examples
xamarinradiobuttonlistxamarin-zebblezebble

How to create a Radio Button List in xamarin zebble.net framework


I want to create a radio button list in zebble.net to force the user to select 1 option among 3 choices of opt1 to opt3 enter image description here

I have checked the documentation and found only the checkbox and optionsList controls.

So I deduct that something like below code can render a radioButtonList

  <OptionsList Id="MyOptionsList" Direction="Horizontal" MultiSelect="false">    
    <CheckBox Id="MyCheckBox1" Checked="false"> </CheckBox>
    <CheckBox Id="MyCheckBox2" Checked="false"> </CheckBox>
    <CheckBox Id="MyCheckBox3" Checked="false"> </CheckBox>
    </OptionsList>

but it will render nothing.what is the problem and how this OptionsList works i could not find any sample showing working usages of this control.

I appreciate can show how this can be done in zebble or in pure xamarin Forms.


Solution

  • Based on the documentation, you should use the DataSource property of the OptionsList.

    So remove the nested CheckBox elements, and instead set the DataSource property:

    <OptionsList Id="MyOptionsList" Direction="Horizontal"
         MultiSelect="false" DataSource="GetMyOptions()" />   
    

    Then in your code behind file, add the method to return the data:

    IEnumerable<string> GetMyOptions()
    {
        return new [] { "My Option1", "My Option2", "My Option3" };
    }