This is a migrated thread and some comments may be shown as answers.
Using Binding and converter in an group template
1 Answer 34 Views
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 1
Pierre asked on 25 Jan 2018, 03:45 PM

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.

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Yana
Telerik team
answered on 29 Jan 2018, 03:12 PM
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
Asked by
Pierre
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or