我正在學習使用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