如何在xamarin表单中使用单选按钮

2024-04-18

创建注册页面,我需要从用户那里获取以下数据。

  • Username
  • Email
  • Password
  • 出生日期
  • Gender
  • 用户角色

对于最后两个参数,我无法找到如何在 Xamarin.Forms 中使用单选按钮。以下是我的注册页面代码。

<StackLayout BackgroundColor="#30af91" Padding="60">


<Entry Text="{Binding FirstName}" Placeholder="First Name"/>
<Entry Text="{Binding LastName}" Placeholder="Last Name"/>
<Entry Text="{Binding UserName}" Placeholder="Last Name"/>
<Entry Text="{Binding Email}" Placeholder="Email" />
<Entry Text="{Binding Password}" Placeholder="Password" IsPassword="True"/>
<Entry Text="{Binding ConfirmPassword}" Placeholder="Confirm Password" IsPassword="True"/>
<DatePicker MinimumDate="1/1/1948" MaximumDate="12/31/2007"/>


<!--Radio buttons for Gender
    1. Male   2.Female-->

<!--Radio Buttons for UserRole
    1. Admin  2.Participant-->

<Button Command="{Binding RegisterCommand}" Text="Register"/>
<Label Text="{Binding Message}" />


</StackLayout>

Xamarin 表单不提供单选按钮。

您可以使用

1)Switch https://developer.xamarin.com/api/type/Xamarin.Forms.Switch/

2)Picker https://developer.xamarin.com/api/type/Xamarin.Forms.Picker/

或任何其他组件来满足您的要求

UPDATE

xamarin forms更新4.6版本已经引入了Radio按钮控件,这里是官方的文档 https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/radiobutton

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在xamarin表单中使用单选按钮 的相关文章

随机推荐