This is a migrated thread and some comments may be shown as answers.

Creating custom control for Gridview

1 Answer 68 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Gopinath
Top achievements
Rank 2
Gopinath asked on 06 Apr 2012, 06:38 AM
I have created a custom control for GridView as shown below

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;


namespace SilverlightApplication1
{
    public class AuthGrid : RadGridView
    {
        public AuthGrid()
        {
            this.DefaultStyleKey = typeof(AuthGrid);
        }


        #region ItemsSource


        public Object ItemsSource
        {
            get
            {
                return (Object)GetValue(ItemsSourceProperty);
            }
            set
            {
                if (value != ItemsSource) SetValue(ItemsSourceProperty, value);
            }
        }
        // Using a DependencyProperty as the backing store for DisplayMemberPath.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ItemsSourceProperty =
            DependencyProperty.Register("ItemsSource", typeof(Object), typeof(AuthGrid), new PropertyMetadata(new PropertyChangedCallback(OnItemSourcecPropertyChanged)));


        private static void OnItemSourcecPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            //
            var AuthGrid = d as AuthGrid;


            if (AuthGrid != null)
            {
                AuthGrid.ItemsSource = e.NewValue as Object;
            }
        }


        #endregion
    }
}


Finally i used that in my page as shown below

 <local:AuthGrid x:Name="RadGridView1" ScrollMode="Deferred"  ItemsSource="{Binding Source={StaticResource DataSource}, Path=Agency}"
IsReadOnly="True" AutoGenerateColumns="True" MinHeight="386" MaxHeight="500"
CanUserFreezeColumns="False" RowIndicatorVisibility="Collapsed" CanUserResizeColumns="False">
            </local:AuthGrid>


  • When i placed the custom control in my page. I didn't see the Grid in the design page. 
  • Secondly the data not binded to the grid view .

If i am wrong in creating a custom control and Dependency properties
can you please provide me the sample project for Creating Custom control for Grid view





1 Answer, 1 is accepted

Sort by
0
Wan
Top achievements
Rank 1
answered on 18 Apr 2012, 06:49 AM
I meet the same problem now.  Anyone can help us ?  Thanks!
Tags
GridView
Asked by
Gopinath
Top achievements
Rank 2
Answers by
Wan
Top achievements
Rank 1
Share this question
or