【发布时间】:2021-01-13 09:37:21
【问题描述】:
在我的 Xamarin 应用程序中,我使用 foreach 循环来获取可用凭据的 name 和 value,然后使用 ListView 在屏幕上打印。
例如
名称 1
值 1
名称 2
价值 2
它工作正常。我现在想要的是改变 Name (_attributes.Add(item.Name.ToString());) 的样式。
例如
姓名 1
价值
名字 2
价值
View.xml
<ListView
SeparatorVisibility="None"
BackgroundColor="#FFFFFF"
ItemsSource="{Binding Attributes}"
HasUnevenRows="true">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label
Text="{Binding .}"
TextColor="#000000"
FontSize="18"
Padding="10" >
</Label>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
ViewModel.cs
foreach (var item in _credential.CredentialAttributesValues)
{
_attributes.Add(item.Name.ToString());
_attributes.Add(item.Value.ToString());
}
private ObservableCollection<string> _attributes = new ObservableCollection<string>();
public ObservableCollection<string> Attributes
{
get
{
return _attributes;
}
set
{
this.RaiseAndSetIfChanged(ref _attributes, value);
}
}
更新
<ViewCell>
<StackLayout>
<Label
Text="{Binding Name}"
TextColor="#000000"
FontSize="18"
Padding="10"
Margin="10,0,0,0">
</Label>
<Label
Text="{Binding Value}"
TextColor="#000000"
FontSize="18"
Padding="10"
Margin="10,0,0,0">
</Label>
</StackLayout>
</ViewCell>
private ObservableCollection<CredentialPreviewAttribute> _attributes = new ObservableCollection<CredentialPreviewAttribute>();
public ObservableCollection<CredentialPreviewAttribute> Attributes
{
get
{
return _attributes;
}
set
{
this.RaiseAndSetIfChanged(ref _attributes, value);
}
}
【问题讨论】:
标签: c# .net xamarin xamarin.forms