【发布时间】:2019-02-01 19:27:05
【问题描述】:
我有一个针对 Android 的 Xamarin.Forms 应用程序,我正在使用 Syncfusion 的 SfRadioGroup 和 SfRadioButton 来向用户提供一些选项。但是,我想提供有关用户可以做出的每个特定选择的更多信息。
我认为实现这一点的一个好方法是在每个 RadioButton 旁边添加一个信息按钮,该按钮将打开一个弹出窗口,其中包含有关该选项的更多信息。
我尝试在 StackLayout 或 Grid 中包含 RadioButton 和信息按钮,但是按钮之间的同步将丢失。 RadioButtons 需要直接放在 SFRadioButtonGroup 中,否则选中其中一个不会取消选中其他。使用 FlowListView 和 DataTemplate 也不起作用。
我在 Wpf 中执行此操作的方法是创建一个扩展 RadioButton 的新控件,对于控件的视图,我将采用默认 Xaml 并对其进行修改以添加一个信息按钮。但是,我找不到 SfRadioButton 的 Xaml 的源代码,这使得扩展控件非常困难。
有没有一种方法可以扩展或自定义 SfRadioButton?如果没有,我有什么替代方法可以在用户选择旁边添加更多信息?
下面是一个简单的代码示例来说明我想要实现的目标(这不起作用,因为 RadioButtons 的直接父级不是 RadioButtonGroup 而是 StackLayouts)
<buttons:SfRadioGroup
Grid.Row="3" Grid.Column="0"
x:Name="radioGroup"
HorizontalOptions="Fill"
Orientation="Vertical"
VerticalOptions="CenterAndExpand"
Margin="10,5,10,0">
<StackLayout Orientation="Horizontal">
<buttons:SfRadioButton
TextColor="{StaticResource AppForegroundColor}"
IsChecked="{Binding Option1, Mode=TwoWay}"
Text="Individual"
VerticalOptions="Center" Margin="1,1,1,1" />
<Button Command="{Binding Path=OpenPopupInfoOption1}"/>
</StackLayout>
<StackLayout Orientation="Horizontal">
<buttons:SfRadioButton
TextColor="{StaticResource AppForegroundColor}"
IsChecked="{Binding Option2, Mode=TwoWay}"
Text="Sum"
VerticalOptions="Center" Margin="1,1,1,1" />
</StackLayout>
<Button Command="{Binding Path=OpenPopupInfoOption2}"/>
</buttons:SfRadioGroup>
【问题讨论】:
-
您能否发布您的 XAML,因为没有它我们只会提出假设!
-
@G.hakim 我添加了一个 Xaml 示例以更好地解释我想要实现的目标。
-
我不认为你可以这样做,因为
buttons:SfRadioGroup需要有buttons:SfRadioButton作为直接孩子才能工作!! -
@G.hakim 是的,我也在最初的问题中写道。这就是为什么我问是否有其他方法可以实现我的目标,也许是通过扩展 SfRadioGroup
标签: android xamarin.forms radio-button syncfusion