Я заполняю ListView объектами из класса, но я не вижу все поля. Некоторые действительно показывают хорошо, некоторые нет вообще. Я подозреваю, что что-то не так с моим форматированием строки. Помощь приветствуется. Кстати, при отладке значения членов класса, которые не отображаются в ListView, также нельзя оценить в Watch, что дает мне только «{...}» вместо конкретного значения -
Я пытался реализовать 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 будут заполнены в соответствии с их привязкой. Упражнения, категории, Reps и Fmax появляются хорошо. Дата и вес вообще не отображаются.
РЕДАКТИРОВАТЬ: Добавлено ядро для RecordedLift