【发布时间】:2021-08-18 22:33:46
【问题描述】:
我想使用 syncfusion 单选按钮在我的 viewModel 中获取所选单选按钮的值,以便我可以根据所选值执行一些逻辑。我似乎无法获得选定的值。请帮忙!
Xaml
<syncfusion:SfRadioGroup x:Name="radioGroup"
BindableLayout.ItemsSource="{Binding Items}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<syncfusion:SfRadioButton
Text="{Binding PaymentMethod}" />
</DataTemplate>
</BindableLayout.ItemTemplate>
</syncfusion:SfRadioGroup>
查看模型
public List<PaymentMthd> Items { get; set; }
Items = new List<PaymentMthd>()
{
new PaymentMthd(){PaymentMethod = "Cash" , id = 1},
new PaymentMthd(){PaymentMethod = "Visa Card" , id = 2},
};
private int _IsChecked;
public int IsChecked
{
get { return _IsChecked; }
set { SetProperty(ref _IsChecked, value); }
【问题讨论】:
-
根据文档,
SfRadioGroup有一个CheckedItem属性 -
现在可以用了吗?
-
您可以在 StateChanged 事件的帮助下实现“获取所选单选按钮的值”的要求。有关详细信息,请参阅下面的 KB 文档。 https://www.syncfusion.com/kb/11037/how-to-notify-the-selection-changes-in-xamarin-forms-radiobutton-sfradiobutton
标签: xamarin mvvm radio-button syncfusion