Reputation: 89
I am binding a Listbox with a List which contains Minutes(200), how do I display relative time, like:
1 month ago
<ListBox x:Name="listBox">
<ListBox.ItemTemplate>
<DataTemplate >
<TextBlock x:Name="TxtDuration" Text="{Binding Duration}"/>
</DataTemplate>
</ListBox.ItemTemplate>
Upvotes: 1
Views: 116
Reputation: 15006
You need something called a relative time converter.
If you search online, you'll find plenty of different implementations. A good one is definitely a part of Callisto toolkit.
You can also check out similar questions on StackOverflow such as this one.
Using a converter is really straightforward.
<TextBlock x:Name="TxtDuration" Text="{Binding Duration, Converter={StaticResource RelativeTimeConverter}}"/>
In this case the RelativeTimeConverter is declared as a static resource somewhere in your app.
Upvotes: 2