I try to display a datetime in the French format dd/MM/AAAA hh:mm:ss.
I have a DateTime in the English format like MM/dd/AAAA hh:mm:ss AM or PM
So I do a parsing like this:
foreach (var _element in listElement)
{
IFormatProvider culture = new CultureInfo("fr-Fr");
string date = _element.DateModifElement.ToString();
_element.DateModifElement = DateTime.Parse(date, culture, DateTimeStyles.NoCurrentDateDefault);
listElementCollection.Add(_element);
}
It works perfectly, so now my DateTime
property in my objects has the French format. So I only need to display the date in the view.
So my ObservableCollection
is binded to a LongListSelector
in the view like this:
ObsvCollectionBdeskElement =new ObservableCollection<GroupType<BdeskElement>>(listElementCollection);
llsElements.ItemsSource = ObsvCollectionBdeskElement;
In the xaml
<phone:LongListSelector
x:Name="llsElements"
ItemsSource="{Binding}"
IsGroupingEnabled="True"
HideEmptyGroups="False"
JumpListStyle="{StaticResource LongListSelectorJumpListStyle}"
LayoutMode="List">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<Grid Margin="0,20,0,0" Background="White">
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu IsZoomEnabled="True" x:Name="ContextMenu" Background="#FF00485A" >
<toolkit:MenuItem Header="renommer" Click="renommer_Click" Foreground="White" />
<toolkit:MenuItem Header="supprimer" Click="supprimer_Click" Foreground="White" />
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
<Grid VerticalAlignment="Center" Grid.Column="1" Margin="10,0,20,0" >
<TextBlock Grid.Row="1" Margin="0,2,0,0" Text="{Binding DateModifElement}" Foreground="{StaticResource C01}" FontSize="16"/>
</Grid>
And the main Grid(layout) has a datacontext which is define by the type of my object. But the problem is that the view still display the english format. So i thought it was the culture of the App which was remmained in English but no, I checked with this line of code and the value is "fr-FR".
string info = CultureInfo.CurrentCulture.Name;