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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Columns binding

Thread ID:

Created:

Updated:

Platform:

Replies:

145129 Jun 7,2019 05:32 PM UTC Jun 17,2019 05:00 PM UTC WPF 5
loading
Tags: SfDataGrid
Tech Shop
Asked On June 7, 2019 05:32 PM UTC


Hi,

I created a custom control to be a base of others controls and this custom control has a SfDataGrid. 
I created custom dependency properties to provide a way to link the ItemSource and Columns properties for my control. 

The dependency property for ItemSource work very well, but the property for columns doesn't work.

What the correct way to implement that property? Bellow the part of code of my properties.

  • Dependency Properties
        // Colunas do Grid
        public Columns GridColmuns
        {
            get
            {
                return (Columns)GetValue(GridColmunsProperty);
            }
            set
            {
                SetValue(GridColmunsProperty, value);
            }
        }

        // Fonte de registros do Grid
        public object GridItemsSource
        {
            get
            {
                return (object)GetValue(GridItemsSourceProperty);
            }
            set
            {
                SetValue(GridItemsSourceProperty, value);
            }
        }

// Colunas do Grid
        public static readonly DependencyProperty GridColmunsProperty =
            DependencyProperty.Register("GridColmuns", typeof(Columns), typeof(ContentView));

        // Fonte de registros do Grid
        public static readonly DependencyProperty GridItemsSourceProperty =
            DependencyProperty.Register("GridItemsSource", typeof(object), typeof(ContentView),
                new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));


  • Custom control template
                           <sf:SfDataGrid
                                AllowFiltering="True"
                                AllowGrouping="True"
                                ColumnSizer="Star"
                                AutoGenerateColumns="False"
                                Columns="{Binding GridColmuns,RelativeSource={RelativeSource TemplatedParent}}"
                                ItemsSource="{Binding GridItemsSource, RelativeSource={RelativeSource TemplatedParent}}"
                                EnableDataVirtualization="True"
                                NavigationMode="Row"
                                ShowBusyIndicator="True"
                                ShowGroupDropArea="True"
                                CellStyle="{StaticResource GridCellStyle}"
                                RowStyle="{StaticResource GridRowControlStyle}"
                                HeaderStyle="{DynamicResource GridHeaderCellControlStyle}">
                            </sf:SfDataGrid>

Shobika Palani [Syncfusion]
Replied On June 10, 2019 01:29 PM UTC

Hi Tech, 

Thank you for contacting Syncfusion Support, 

We have analyzed your query related to column binding and we are able to reproduce the reported issue from our end. We are currently working on this with high priority  and we will update you with more details on 12th June,2019. 

We will appreciate your patience until then. 

Regards,
Shobika. 


Shobika Palani [Syncfusion]
Replied On June 12, 2019 02:05 PM UTC

Hi Tech, 
 
We regret for the inconvenience caused. 
 
Still we are validating the reported issue in our end and we need two more business days to finalize the behavior. We will update you with more details on 14th June,2019. 
 
We will appreciate your patience until then. 
 
Regards, 
Shobika. 


Tech Shop
Replied On June 12, 2019 04:35 PM UTC

Thank you

Jagadeesan Pichaimuthu [Syncfusion]
Replied On June 13, 2019 11:16 AM UTC

Hi Tech, 
 
Thanks for your update. 
 
We will update you with more details on June 14th, 2019.  
  
We will appreciate your patience until then. 
 
Regards, 
Jagadeesan 


Shobika Palani [Syncfusion]
Replied On June 17, 2019 05:00 PM UTC

Hi Tech, 

Thanks for your patience. 

We have analyzed your reported issue with binding columns when grid is loaded in ControlTemplate. And the reported issue can be resolved by binding columns via attached property. Please refer to the below code example 

C#: 
internal static class BindableColumns 
    { 
        public static Columns GetColumns(DependencyObject obj) 
        { 
            return (Columns)obj.GetValue(ColumnsProperty); 
        } 
 
        public static void SetColumns(DependencyObject obj, Columns value) 
        { 
            obj.SetValue(ColumnsProperty, value); 
        } 
 
        // Using a DependencyProperty as the backing store for Columns.  This enables animation, styling, binding, etc... 
        public static readonly DependencyProperty ColumnsProperty = 
            DependencyProperty.RegisterAttached("Columns", typeof(Columns), typeof(BindableColumns), new PropertyMetadata(null, OnColumnsPropertyChanged)); 
 
        public static void OnColumnsPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) 
        { 
            var dataGrid = obj as SfDataGrid; 
            if(dataGrid != null) 
                dataGrid.Columns = args.NewValue as Columns; 
        } 
    } 

XAML: 
<ControlTemplate> 
            <Grid> 
                <sf:SfDataGrid x:Name="grid"  
                                AllowFiltering="True" 
                                AllowGrouping="True" 
                                ColumnSizer="Star"  
                                AutoGenerateColumns="False"                                 
                                ItemsSource="{Binding GridItemsSource, RelativeSource={RelativeSource TemplatedParent}}" 
                                local:BindableColumns.Columns="{Binding GridColumns, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                                EnableDataVirtualization="True" 
                                NavigationMode="Row" 
                                ShowBusyIndicator="True" 
                                ShowGroupDropArea="True"> 
                </sf:SfDataGrid> 
            </Grid> 
        </ControlTemplate> 

Also please find sample for the same from the below link 
Sample Link: 

Regards, 
Shobika. 


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

Live Chat Icon For mobile
Live Chat Icon