【发布时间】:2021-11-16 11:40:13
【问题描述】:
我在 Xamarin 表单中有一个简单的列表视图。定义如下。
<ListView x:Name="lvRadio" Grid.Row="1"
SeparatorVisibility="None"
VerticalOptions="CenterAndExpand"
HorizontalOptions="StartAndExpand" HasUnevenRows="True" BackgroundColor="#ffffff"
HeightRequest="300">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout BackgroundColor="White">
<RadioButton BackgroundColor="#ffffff"
Content="{Binding Description}"
FontFamily="Roboto" FontSize="16" TextColor="Black"
></RadioButton>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
在后面的代码中,我将列表视图绑定如下
List<CommonModel> temp = new List<CommonModel>();
CommonModel model;
model = new CommonModel();
model.Description = "Radio 1";
temp.Add(model);
model = new CommonModel();
model.Description = "Radio 2";
temp.Add(model);
model = new CommonModel();
model.Description = "Radio 3";
temp.Add(model);
lvRadio.ItemsSource = null;
lvRadio.ItemsSource = temp;
现在,当我更新 ItemsSource 时,所有单选按钮都丢失了。 任何帮助将不胜感激。
【问题讨论】:
-
“所有单选按钮都丢失”是什么意思?
-
Listview 不呈现任何单选按钮