Using Binding and converter in an group template

2 posts, 1 answers
  1. Pierre
    Pierre avatar
    261 posts
    Member since:
    Apr 2007

    Posted 25 Jan 2018 Link to this post

    Hi, I try to format a dateTime in my group template for Telerik Listview in Xamarin Forms.

        <ContentPage.Resources>
            <ResourceDictionary>
                <converters:HexToColorConverter x:Key="cnvHexToColor"></converters:HexToColorConverter>
                <converters:DateToGroupeConverter x:Key="cnvDateToGroupe"></converters:DateToGroupeConverter>
            </ResourceDictionary>
        </ContentPage.Resources>
     
    AND ON THE LISTVIEW
                <telerikDataControls:RadListView.GroupDescriptors>
                    <telerikListView:PropertyGroupDescriptor PropertyName="DateOnlyPlanif" SortOrder="Ascending" />
                </telerikDataControls:RadListView.GroupDescriptors>
                <telerikDataControls:RadListView.GroupHeaderTemplate>
                    <DataTemplate>
                        <Grid BackgroundColor="#C1C1C1">
                            <Label Text="{Binding , Converter={StaticResource cnvDateToGroupe}}" TextColor="#303030" FontSize="Medium" HorizontalOptions="Center"/>
                        </Grid>
                    </DataTemplate>
                </telerikDataControls:RadListView.GroupHeaderTemplate>

     

    But the converter is never called. 

    public class DateToGroupeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                string retour = "";
                DateTime DatePlanifDebut = (DateTime)value;
     
                if (DatePlanifDebut == DateTime.MinValue)
                {
                    retour = "- Aucune date planifiée -";
                }
                else
                {
                    retour = DatePlanifDebut.Date.ToString("dddd, dd MMMM, yyyy", CultureInfo.CurrentCulture);
                }
     
                return retour;
            }
            catch (Exception ex)
            {
                ErrorHandling.LogError(ex);
                return "- Aucune date planifiée -";
            }
        }
     
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

     

    Any idea?

    The same converter in an colum of the grid work ok.

     

  2. Answer
    Yana
    Admin
    Yana avatar
    5013 posts

    Posted 29 Jan 2018 Link to this post

    Hi Pierre,

    Please try setting the converter like this:

    <Label Text="{Binding ., Converter={StaticResource cnvDateToGroupe}}" TextColor="#303030" FontSize="Medium" HorizontalOptions="Center"/>

    I have also attached my test application as a reference.

    Let me know whether this helps.

    Regards,
    Yana
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top