c# - Xamarin iOS 项目中的 BindableRadioGroup
问题描述
我在一个 Xamarin 项目中工作。以前该项目只有 Android,现在我还需要包含同一应用程序的 iOS 版本。在我的应用程序页面中,有一个单选按钮的动态列表。我使用的组件是 XLabs.Forms 包的 BindableRadioGroup。
这是 xaml 页面中的标记:
<ScrollView Orientation = "Vertical" VerticalOptions="Start" HeightRequest="250">
<controls:BindableRadioGroup SelectedIndex="{Binding SelectedAnomaly, Mode=TwoWay}" ItemsSource="{Binding AnomalyList, Mode=TwoWay}" />
</ScrollView>
我的 ViewModel 中的代码:
public DomainFEModel SelectedAnomalyDomain
{
get { return _selectedAnomalyDomain; }
set { SetProperty(ref _selectedAnomalyDomain, value); }
}
public ObservableCollection<string> AnomalyList
{
get { return _anomalyList; }
set { SetProperty(ref _anomalyList, value); }
}
这是前端模型:
public class DomainFEModel : FEModel
{
public string key { get; set; }
public string description { get; set; }
}
该列表是从数据库中动态填充的。在 Android 版本中一切正常:
但在 iOS 版本中不起作用:
我无法选择列表中的元素。如何在 iOS 中解决这个问题?还有另一种方法可以创建可以在 Android 和 iOS 版本中使用的单选按钮动态列表?
解决方案
现在,Xamarin 已经发布了新的RadioButton
控件。尝试将 Xamarin.Forms 更新到最新版本,您可以在此处查看文档和此处的类文档。
要动态添加 RadioButtons,您可以按如下方式创建它们:
// create 5 radiobuttons
for (int i = 0; i < 5; i++)
{
RadioButton radioButton = new RadioButton();
radioButton.Content = $"Content{i}";
if (i == 1) // check the 2rd one
radioButton.IsChecked = true;
MyLayout.Children.Add(radioButton);
}
推荐阅读
- sql - 大查询 - 重复记录到单独的列
- java - 为什么我们在 Assertj Swing 测试中偶尔会失败?
- angular6 - 如何从父表单提交按钮提交子表单
- delphi - 您如何修改 Delphi 面板,以便 Alignment := taRightJustify 呈现带有轻微右边距的 Caption?
- python - 如何使用 pandas 的列与列列表和值列表之间的匹配来填充数据框?
- android - 从viewholder回调后如何在Fragment中再次连接ViewModel
- lisp - 导致粘液崩溃的条件语句
- javascript - 如何使用 `react-share` 包在 Twitter 和 Facebook 上分享图片和描述?
- python - 在 pd.read_table(url) 的 Pycharm 问题中
- ruby-on-rails - 访问类属性以在 Rails 关注中定义实例方法