In my xaml form i have the following:
<ListView x:Name="listView" ItemsSource="{Binding Path=AllResults}" ItemSelected="OnEmployeeListItemSelected" HorizontalOptions="StartAndExpand" HasUnevenRows="true">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout VerticalOptions="StartAndExpand">
<Label Text="{Binding Result}" HorizontalOptions="FillAndExpand" Font="{StaticResource fontL}" TextColor="{Binding TestResult, Converter={StaticResource resultMapper}}" />
<Label Text="{Binding Path=StartedOn, StringFormat='dd-MM-yyy @ HH:mm:ss.fff'}" Font="Medium" />
<Label Text="Test went on for {Binding NoOfHours}" Font="Medium"/>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
AllResults, which is the binding for the listview is a List type that contains a ORM based objects from the DB.
public class Result
{
[PrimaryKey, AutoIncrement]
public int TestID { get; set; }
public DateTime StartedOn { get; set; }
public DateTime EndedOn { get; set; }
public TimeSpan NoOfHours{ get; set; }
public string TestResult{ get; set; }
public Result ()
{
StartedOn = DateTime.Now;
NoOfHours = TimeSpan.Zero;
TestResult = "";
}
}
I need help for two things:
- For the date I tried to use the method mentioned here, but it just displays as "dd-MM-yyy @ HH:mm:ss.fff"
- To show "Test went for of x", where x is a Time of hours
NoOfHours
is of theTimeSpan
type which uses different format specifiers.<Label Text="{Binding NoOfHours, StringFormat=Test went on for: {0:hh}}"/>