We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to create a Binding of Custompattern in TreeGridDateTimeColumn

Thread ID:

Created:

Updated:

Platform:

Replies:

141962 Jan 13,2019 11:29 AM UTC Jan 17,2019 05:08 AM UTC WPF 4
loading
Tags: SfTreeGrid
MrHessellund
Asked On January 13, 2019 11:29 AM UTC

Hi,

Trying to do this:

<syncfusion:TreeGridDateTimeColumn MappingName="Date" HorizontalHeaderContentAlignment="Left" ColumnSizer="AutoFillColumn" AllowNullValue="True" AllowEditing="True" CanEdit="True" Pattern="CustomPattern" CustomPattern="{Binding Path=DateFormat}" />

Whereas Date and DateFormat are both Properties of the ItemsSource used by the SfTreeGrid.

However, the DateFormat seems not to apply.

Goal is to be able to have per cell CustomPattern in the DateTimeColumn.

What am I missing?

Please advise.

Best regards,
Johannes

Arulraj A [Syncfusion]
Replied On January 14, 2019 10:36 AM UTC

Hi Johannes, 
 
Thank you for contacting Syncfusion support. 
 
We have analyzed your query and you can achieve your requirement by setting the CustomPattern to the GridDataTimeColumn by using the below code snippets. 
 
Solution 1:  
Bind the DateFormats from ViewModel by using the below code snippets. 
 
<syncfusion:TreeGridDateTimeColumn MappingName="DOB" TextAlignment="Right"  
                                    HorizontalHeaderContentAlignment="Left" 
                                    ColumnSizer="AutoFillColumn"  
                                    AllowNullValue="True"  
                                    AllowEditing="True" CanEdit="True" 
                                    CustomPattern="{Binding Pattern}" Pattern="CustomPattern" /> 
 
 
Solution 2: 
Bind the DateFormats from Model ie (RowData) by using the below code snippets. 
<syncfusion:TreeGridDateTimeColumn MappingName="DOB"  
                                    HeaderText="DOB WITH ROWDATA" 
                                    TextAlignment="Right"  
                                    HorizontalHeaderContentAlignment="Left" 
                                    ColumnSizer="AutoFillColumn"  
                                    AllowNullValue="True"  
                                    AllowEditing="True" CanEdit="True" 
                                    CustomPattern="{Binding Converter={StaticResource converter}}" Pattern="CustomPattern" /> 
 
Converter codes: 
class Converter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
        var employee = value as Employee; 
        if (employee != null) 
        { 
            return employee.Pattern; 
        } 
        else 
            return ""; 
    } 
 
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
        return value; 
    } 
} 
 
Please find the Sample from the below location. 

Arulraj A 


MrHessellund
Replied On January 14, 2019 08:42 PM UTC

Hi,

Thank you for this.

It seems the best option should be to go with the converter, in order to get pattern per cell.

However, the DOB WITH ROWDATA does not work on my setup.

In

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
        var employee = value as Employee; 
        if (employee != null) 
        { 
            return employee.Pattern; 
        } 
        else 
            return ""; 
    }

"value" seems to be the viewmodel/datacontext, and not the specific Employee object of the relevant row.

I am testing with latest Syncfusion essential studio 2018 vol 4.

Please advise.
Best regards

MrHessellund
Replied On January 16, 2019 06:23 AM UTC

Hi,

Figured it out.

In XAML did this:

<syncfusion:TreeGridDateTimeColumn MappingName="DOB"
                                                HeaderText="DOB WITH ROWDATA"
                                                TextAlignment="Right"
                                                HorizontalHeaderContentAlignment="Left"
                                                ColumnSizer="AutoFillColumn"
                                                AllowNullValue="True"
                                                AllowEditing="True" CanEdit="True"
                                               DisplayBinding="{Binding Converter={StaticResource converter}}"
                                                 />

In converter:

class Converter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var employee = value as Employee;
            if (employee != null)
            {
                if (employee.DOB != null)
                    return employee.DOB.Value.ToString(employee.Pattern);
                return "Undated";
            }
            else
                return "";
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }
    }


Thanks for the pointer.

Best regards,
Johanne

Arulraj A [Syncfusion]
Replied On January 17, 2019 05:08 AM UTC

Hi Johanne,

Thanks for the update.

Please feel free to contact us in case of any further difficulty. We'll be glad to assist you.

Regards,
Arulraj A

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;