change format of label from yyyy-mm-dd to dd-mm-yyyy in xamrin forms

Prashant Sharma 66 Reputation points
2021-04-30T18:25:16.933+00:00

I am trying to convert the format of a date in xaml by below code but it reponse nothing. I am sharing my xaml code. Thanks in advance.

                  <CollectionView x:Name="ColView" ItemsSource="{Binding BindSaleEntryList, Mode=TwoWay}" 
                                    SelectionMode="Single" VerticalOptions="Start">

                    <CollectionView.ItemsLayout>
                        <GridItemsLayout Orientation="Vertical" Span="1" VerticalItemSpacing="5" />
                    </CollectionView.ItemsLayout>

                    <CollectionView.ItemTemplate>
                        <DataTemplate>

                            <Frame x:Name="s" OutlineColor="Silver" HorizontalOptions="FillAndExpand" 
                                       CornerRadius="10" BackgroundColor="White" Padding="5,5,25,5">

                                <Grid HorizontalOptions="FillAndExpand" Padding="20,5,-20,5">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="1*" />
                                        <ColumnDefinition Width="1*" />
                                        <ColumnDefinition Width="1*" />

                                    </Grid.ColumnDefinitions>

                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="1*" />
                                    </Grid.RowDefinitions>



                                    <Label HorizontalOptions="FillAndExpand" VerticalOptions="Center" Margin="-20" 
                                                   FontAttributes="Bold" FontSize="14" Grid.Row="0"
                                                   Grid.Column="0" Text="{Binding CustomerName}" Padding="10,0,0,0"></Label>
                                    <Label HorizontalOptions="FillAndExpand" VerticalOptions="Center" 
                                                   FontAttributes="Bold" FontSize="14" Grid.Row="0" 
                                                   Grid.Column="1" 
                                                   Text="{Binding SaleDate, StringFormat='{0:MMMM d, yyyy}'}"                                                      
                                                   Padding="-15,0,0,0"></Label>



                                    <Label HorizontalOptions="FillAndExpand" VerticalOptions="Center" 
                                                   FontAttributes="Bold" FontSize="14" Grid.Row="0" 
                                                   Grid.Column="2" Text="{Binding ProductName}" 
                                                   Padding="10,0,0,0"></Label>
                                    <Label HorizontalOptions="FillAndExpand" VerticalOptions="Center" 
                                                   FontAttributes="Bold" FontSize="14" Grid.Row="0" 
                                                   Grid.Column="3" Text="{Binding Total}" 
                                                   Padding="20,0,0,0"></Label>
                                </Grid>

                            </Frame>




                        </DataTemplate>
                    </CollectionView.ItemTemplate>
                </CollectionView>
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,253 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,751 Reputation points
    2021-05-03T07:41:23.147+00:00

    Hello,

    Welcome to Microsoft Q&A!

    Simply change your code as below

       Text="{Binding SaleDate,StringFormat='{0:d-M-yyyy}'}"  
    

    It works fine on my side .

    93321-capture.png

    Best Regards,
    Cole Xia


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.