_variantsList.Add(new Variants() { Name = "Size", options = size_options, GroupKey = "Size" });
_variantsList.Add(new Variants() { Name = "Sweetness Level", options = sweetness_options , GroupKey = "Sweetness Level"}); |
public class ViewModel1 {
SfRadioGroupKey sizeKey = new SfRadioGroupKey();
SfRadioGroupKey sweetnessLevelKey = new SfRadioGroupKey();
private ObservableCollection<Variants> _VariantsList;
public ObservableCollection<Variants> VariantsList
{
get { return _VariantsList; }
set { _VariantsList = value; }
}
public ViewModel1()
{
VariantsList = new ObservableCollection<Variants>();
ObservableCollection<Options> size_options = new ObservableCollection<Options>();
size_options.Add(new Options() { Name = "Medium", Price = "+25.00" });
size_options.Add(new Options() { Name = "Large", Price = "+45.00" });
size_options.Add(new Options() { Name = "Grande", Price = "+65.00" });
ObservableCollection<Options> sweetness_options = new ObservableCollection<Options>();
sweetness_options.Add(new Options() { Name = "25%", Price = "+0.00" });
sweetness_options.Add(new Options() { Name = "50%", Price = "+0.00" });
sweetness_options.Add(new Options() { Name = "75%", Price = "+0.00" });
sweetness_options.Add(new Options() { Name = "100%", Price = "+0.00" });
VariantsList.Add(new Variants() { Name = "Size", options = size_options, GroupKey = sizeKey });
VariantsList.Add(new Variants() { Name = "Sweetness Level", options = sweetness_options, GroupKey = sweetnessLevelKey });
}
} |
XAML:
<StackLayout BindableLayout.ItemsSource="{Binding VariantsList}" VerticalOptions="Center" HorizontalOptions="Center" WidthRequest="550">
...
<StackLayout x:Name="stacklayout" BindableLayout.ItemsSource="{Binding options}">
<BindableLayout.ItemTemplate>
<DataTemplate>
..
<buttons:SfRadioButton Grid.Column="0"
HorizontalTextAlignment="Start"
Text="{Binding Name}"
GroupKey="{Binding Source={x:Reference stacklayout}, Path=BindingContext.GroupKey}"
Margin="15,0,0,0"/>
...
</DataTemplate>
...
</StackLayout> |