Xamarin Xaml将两个以上的属性绑定到TextCell
我想将2个以上的属性绑定到我的列表中,这是否可能检查下面的代码Xamarin Xaml将两个以上的属性绑定到TextCell,xaml,xamarin,xamarin.forms,Xaml,Xamarin,Xamarin.forms,我想将2个以上的属性绑定到我的列表中,这是否可能检查下面的代码 <ListView x:Name="APRListView" Grid.Row="4" Grid.RowSpan="5" Grid.Column="0" Grid.ColumnSpan="4" Margin="10,-20,-50,-300">
<ListView x:Name="APRListView"
Grid.Row="4"
Grid.RowSpan="5"
Grid.Column="0"
Grid.ColumnSpan="4"
Margin="10,-20,-50,-300">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell
Text="{Binding ProductName}"
Detail="{Binding Monthly}"
/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
还有其他方法吗
我还想在细节中添加文本,也就是在细节中=“{Binding Monthly}”我希望它在前端返回-Monthly:{Monthly}使用
ViewCell
来编写自己的布局,并使用标签和格式化文本在一个标签中包含多个文本源
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text="{Binding ProductName}" />
<Label Text="{Binding Monthly}" />
<Label.FormattedText>
<FormattedString>
<Span Text="Monthly: " />
<Span Text="{Binding Monthly}" />
</FormattedString>
</Label.FormattedText>
</StackLayout>
</ViewCell>
</DataTemplate>
根据Jason的代码,您也可以尝试在标签中使用绑定,请查看:
<ListView HasUnevenRows="True" ItemsSource="{Binding products}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Margin="10" Text="{Binding ProductName}" />
<Label Text="{Binding Monthly, StringFormat='Monthly: {0:N}'}" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
截图为:
请检查我的代码,它将帮助您找到到textcell的多个绑定:
XAML代码
<ListView HasUnevenRows="True" ItemsSource="{Binding DemoItems}" SeparatorVisibility="None">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding name}" TextColor="Red" Detail="{Binding details}" DetailColor="Green">
</TextCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
视图模型代码:
public class TestPageViewModel : PlusDoctor.ViewModels.BaseViewModel
{
private ObservableCollection<DemoDTO> demoItems;
public ObservableCollection<DemoDTO> DemoItems
{
get { return demoItems; }
set
{
demoItems = value;
OnPropertyChanged();
}
}
public TestPageViewModel()
{
DemoItems = new ObservableCollection<DemoDTO>() {
new DemoDTO(){ name="abc", details="ABC details" }, new DemoDTO(){ name="xyz", details="XYZ details" } };
}
}
输出:
希望它对你有用
谢谢
public class TestPageViewModel : PlusDoctor.ViewModels.BaseViewModel
{
private ObservableCollection<DemoDTO> demoItems;
public ObservableCollection<DemoDTO> DemoItems
{
get { return demoItems; }
set
{
demoItems = value;
OnPropertyChanged();
}
}
public TestPageViewModel()
{
DemoItems = new ObservableCollection<DemoDTO>() {
new DemoDTO(){ name="abc", details="ABC details" }, new DemoDTO(){ name="xyz", details="XYZ details" } };
}
}
public class DemoDTO
{
public string name { get; set; }
public string details { get; set; }
}