我正在开发一个Xamarin.Forms应用。我的要求是显示一个可用作Json的对象列表,并为每个列表项添加一个复选框,当选中该项时,我想将该项存储在一个单独的本地DB中以备将来使用。
这是我的项目模板。
private static X509Certificate2Collection FindRecipientCerts(
X509Certificate2Collection haystack,
RecipientInfo recipient)
{
SubjectIdentifier identifier = recipient.RecipientIdentifier;
if (identifier.Type == SubjectIdentifierType.IssuerAndSerialNumber)
{
X509Certificate2Collection coll = new X509Certificate2Collection();
X509IssuerSerial issuerSerial = (X509IssuerSerial)identifier.Value;
#if !CLONE_REQUIRED
foreach (X509Certificate2 cert in haystack)
{
if (cert.SerialNumber == issuerSerial.SerialNumber &&
cert.Issuer == issuerSerial.IssuerName)
{
coll.Add(cert);
}
}
return coll;
#else
// To reduce the number of clones generated, do a local filter on IssuerName, then
// use the cloning Find method for SerialNumber.
foreach (X509Certificate2 cert in haystack)
{
if (cert.Issuer == issuerSerial.IssuerName)
{
coll.Add(cert);
}
}
return coll.Find(
X509FindType.FindBySerialNumber,
issuerSerial.SerialNumber,
false);
#endif
}
else if (identifier.Type == SubjectIdentifierType.SubjectKeyIdentifier)
{
return haystack.Find(
X509FindType.FindBySubjectKeyIdentifier,
identifier.Value,
false);
}
else
{
throw new InvalidOperationException();
}
}
这是<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid VerticalOptions="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<controls:CheckBox x:Name="Completed" />
<Label x:Name="index"
HorizontalOptions="Center"
Text="{Binding index}"
Grid.Column="1"/>
<Label x:Name="title"
Text="{Binding title}"
Grid.Column="2" />
<Label x:Name="count"
HorizontalOptions="Center"
Text="{Binding count}"
Grid.Column="3" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
的项目来源。
ListView
我的问题是:
SurahNames.ItemsSource = viewModel.surahs;
的bool值? 答案 0 :(得分:0)
您可以像这样绑定所选项目
private object _selectedItem;
public object SelectedItem
{
get { return _selectedItem; }
set
{
cast to your model
YourModel val=(YourModel)value;
//checked is the new proprety that you added to ur model
val.Checked=true;
dosmthwithvalue(val);
//this to unselect the item in listview /remove color
_selectedItem = null;
OnPropertyChanged("SelectedItem");
}
}
对于CheckBox
,您需要将check属性添加到模型中
我没有测试它,也许这不是最佳解决方案,但我认为它会做你想要的。