【发布时间】:2020-11-22 08:17:32
【问题描述】:
我有一个带有自定义 ViewCell 的 ListView。绑定的 ItemsSource 是 Biller Class 的列表。只有当我在屏幕上显示超过 10 个项目并且我正在滚动屏幕时,才会发生 ViewCell 重叠。
Biller 类定义
public class Biller
{
public string BillerId { get; set; }
public string BillerName { get; set; }
public string BillerShortName { get; set; }
public string BillerLogoUrl { get; set; }
}
自定义 ViewCell 定义
public class CustomBillCell : ViewCell
{
public CustomBillCell()
{
// instantiate each of our views
var billerShortNameLabel = new Label();
var billerIdLabel = new Label();
var billerNameLabel = new Label();
var verticalLayout = new StackLayout();
var horizontalLayout = new StackLayout();
var billFrame = new Frame();
var viewBillButton = new Button
{
Text = "View Bill",
HorizontalOptions = LayoutOptions.EndAndExpand
};
// set bindings
billerShortNameLabel.SetBinding(Label.TextProperty, new Binding("BillerShortName"));
billerIdLabel.SetBinding(Label.TextProperty, new Binding("BillerId"));
billerNameLabel.SetBinding(Label.TextProperty, new Binding("BillerName"));
viewBillButton.SetBinding(ClassIdProperty, new Binding("BillerName"));
viewBillButton.Clicked += ViewBillButtonClicked;
// Set properties for desired design
billerShortNameLabel.FontSize = 20;
billerShortNameLabel.FontFamily = "d-din-bold";
verticalLayout.Children.Add(billerShortNameLabel);
verticalLayout.Children.Add(billerNameLabel);
verticalLayout.Children.Add(billerIdLabel);
verticalLayout.Spacing = 2;
horizontalLayout.Orientation = StackOrientation.Horizontal;
horizontalLayout.Children.Add(verticalLayout);
horizontalLayout.Children.Add(viewBillButton);
// Set properties for Frame
billFrame.HasShadow = false;
billFrame.CornerRadius = 10;
billFrame.BorderColor = Color.FromHex("#0C0555");
billFrame.Content = horizontalLayout;
billFrame.Margin = 14;
View = billFrame;
}
[Obsolete]
private async void ViewBillButtonClicked(object sender, EventArgs e)
{
var billSignUpPage = new BillSignUpPage();
Button btn = sender as Button;
billSignUpPage.BindingContext = btn;
await Application.Current.MainPage.Navigation.PushModalAsync(billSignUpPage);
}
}
【问题讨论】:
-
更改 ListView 的缓存策略
标签: c# listview xamarin.forms data-binding frontend