Click here to Skip to main content
15,886,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created one custom control for paging data grid in WPF but it is not working. Please help me.

I am using my custom control as follows:

<Window x:Class="Frames.Masters.AreaWindow"
xmlns:uc="clr-namespace:Frames.UserControls">
...
<Grid.Resources>
      <uc:PagedData x:Key="database" />
</Grid.Resources>
...
<xcdg:DataGridControl>
</xcdg:DataGridControl>
<uc:PagingControl x:Name="pager" Grid.Row="2" Height="25" ItemsSource="{Binding ocArea}"
PageContract="{StaticResource database}" />

I am using Xceed data grid above. Then declaring my custom control which is nothing but an user control which I have created which includes buttons and text boxes. I am assigning it to ObservableCollection which has 5 records.

My user control is PagingControl.xaml.
Its cs file is like, (I am giving partial code here)

public partial class PagingControl : UserControl
{
public static DependencyProperty ItemsSourceProperty;
public ObservableCollection<object> ItemsSource
        {
            get
            {
                return GetValue(ItemsSourceProperty) as ObservableCollection<object>;
            }
            set
            {
                SetValue(ItemsSourceProperty, value);
            }
        }

 static PagingControl()
        {
            ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(ObservableCollection<object>), typeof(PagingControl), new PropertyMetadata(new ObservableCollection<object>()));

}

public IPageControlContract PageContract
        {
            get
            {
                return GetValue(PageContractProperty) as IPageControlContract;
            }
            set
            {
                SetValue(PageContractProperty, value);
            }
        }

private void SetDefaultValues()
        {
                        PageContract.SetRecordSource(ItemsSource);
}

private void Navigate(PageChanges change)
        {
            uint TotalRecords;
            short NewPageSize;

            if (PageContract == null)
            {
                return;
            }

            TotalRecords = PageContract.GetTotalCount();
}
}

Here above IPageControlContract is an interface which is like below:
public interface IPageControlContract
    {
        void SetRecordSource(ObservableCollection<object> ocSource);
        uint GetTotalCount();
        ICollection<object> GetRecords(uint StartIndex, short NumberOfRecords);
    }


Then I implement it as:
public class PagedData: IPageControlContract
    {
        ObservableCollection<object> oc;

        public void SetRecordSource(ObservableCollection<object> ocSource)
        {
            oc = ocSource;
        }

        public uint GetTotalCount()
        {
            return (uint)oc.Count;
        }
}
And this PagedData class is what I am referring in xaml via static resource. Now when I am debugging I am getting oc as null inside PagedData or oc having count zero even though my ocArea which is of type of some custom class 'Area' has 5 records. Now I have declared Observable Collection as type of object because I want my  control to act on any type of object for paging.
Posted
Comments
kunal2u 4-Jan-14 12:51pm    
@RyanDev: Can you please help?
kunal2u 4-Jan-14 12:53pm    
@Nelek: Can you please help?
kunal2u 4-Jan-14 12:53pm    
@Richard C Bishop: Can you please help?
kunal2u 4-Jan-14 12:53pm    
@Sergey Alexandrovich Kryukov: Can you please help?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900