我正在学习使用Xamarin,并且正在制作一个简单的定制细胞。但是,当我运行应用程序时,没有任何设置为ListViews ItemsSource的信息显示。我想知道是否存在与我绑定信息的方式有关的问题,或者是否与我构建自定义单元格的方式有关。定制Xamarin细胞问题
这里是细胞类:
public class ButtonCell : ViewCell
{
#region Constructors
public ButtonCell()
{
//Button bg = new Button();
Label title = new Label()
{
TextColor = Color.Black,
FontSize = 12,
YAlign = TextAlignment.Start
};
Label description = new Label()
{
TextColor = Color.Black,
FontSize = 12,
YAlign = TextAlignment.End
};
title.SetBinding(Label.TextProperty, new Binding("Title"));
description.SetBinding(Label.TextProperty, new Binding("Budget"));
Grid labelLayout = new Grid()
{
/*VerticalOptions = LayoutOptions.Center,*/
Padding = new Thickness(5, 0, 5, 10),
Children =
{
title,
description
}
};
View = labelLayout;
/*Grid grid = new Grid()
{
Padding = new Thickness(5, 0, 5, 10),
Children =
{
bg,
labelLayout
}
};*/
}
#endregion
}
这里是我想从在列表视图中显示的信息的类:
public class Bucket
{
#region Public Variables
public string Title;
public float Budget;
public BucketType Type;
public BucketCategory Category;
#endregion
#region Constructors
public Bucket()
{
Title = "";
Budget = 0;
Type = (BucketType)0;
Category = (BucketCategory)0;
}
public Bucket(string title, float budget, BucketType type, BucketCategory category)
{
Title = title;
Budget = budget;
Type = type;
Category = category;
}
#endregion
}
public enum BucketType
{
Flexible = 0,
Fixed
}
public enum BucketCategory
{
Bills = 0,
Food,
Hobbies
}
当我初始化列表视图中,它显示适当数量的小区。但是,没有任何信息显示。再次,我不确定它是一个绑定问题还是格式问题。
感谢您的帮助提前!
您的可绑定值(标题,预算等)需要是公共属性,而不仅仅是公共成员变量 – Jason