我正在用类中的对象填充ListView,但是看不到所有字段。有些确实表现很好,有些根本没有。我怀疑我的字符串格式有问题。感谢帮助。附带说明,调试时,也无法在Watch中评估未在ListView中显示的类成员的值,只给我一个“ {...}”,而不是具体值-
我尝试实现DatetimeToStringConverter,正如在不同线程上所暗示的那样,但这对我不起作用。
C#
public partial class LiftLog : ContentPage
{
ObservableCollection<RecordedLift> RecordList;
public LiftLog()
{
RecordList = new ObservableCollection<RecordedLift>();
InitializeComponent();
RecordedLifts.ItemsSource = RecordList;
}
}
XAML:
<ListView x:Name="RecordedLifts" ItemSelected="RecordedLifts_ItemSelected" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<!-- <TextCell Text="{Binding Category}" Detail="{Binding Exercise}"/>-->
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Clicked="MenuItem_Clicked" CommandParameter="{Binding .}" Text="More" />
<MenuItem Clicked="MenuItem_Clicked_1" CommandParameter="{Binding .}" Text="Delete" IsDestructive="True" />
</ViewCell.ContextActions>
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<StackLayout HorizontalOptions="StartAndExpand">
<Label Text="{Binding Exercise}"/>
<Label Text="{Binding Category}" TextColor="Blue"/>
</StackLayout>
<StackLayout HorizontalOptions="CenterAndExpand" Orientation="Vertical">
<Label Text="{Binding Weight, StringFormat='{}{0:0} KG'}" />
<Label Text="{Binding Reps, StringFormat='{}{0:0} Reps'}" />
</StackLayout>
<StackLayout HorizontalOptions="EndAndExpand" Orientation="Vertical">
<Label Text="{Binding Fmax, StringFormat='1RM = \{0:0.00\}'}" />
<Label Text="{Binding Date, StringFormat='Lifted on-\{0:dd/MM/yy}'}" TextColor="Red" />
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
public class RecordedLift
{
public string Category { get; set; }
public DateTime Date { get; set; }
public int Reps { get; set; }
public double Weight { get; set; }
public string Exercise { get; set; }
public double Fmax { get; set; }
public string Detail {
get
{
string result = string.Format("{0:F2} ({1:F0} Reps with {2:F2} KG", Fmax, Reps, Weight);
return result;
}
set { }
}
}
我希望ListView中的所有标签都根据其绑定填充。运动,类别,重复次数和Fmax很好地显示出来。日期和权重根本不显示。
编辑:为RecordedLift添加了核心