My WPF Paging Custom Control Not Working
 
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:
 
xmlns:uc="clr-namespace:Frames.UserControls">
...

     

...


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 ItemsSource
        {
            get
            {
                return GetValue(ItemsSourceProperty) as ObservableCollection;
            }
            set
            {
                SetValue(ItemsSourceProperty, value);
            }
        }
 
static PagingControl()
        {
            ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(ObservableCollection), typeof(PagingControl), new PropertyMetadata(new ObservableCollection()));
 
}
 
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 ocSource);
        uint GetTotalCount();
        ICollection GetRecords(uint StartIndex, short NumberOfRecords);
    }
 

Then I implement it as:
public class PagedData: IPageControlContract
    {
        ObservableCollection oc;
 
        public void SetRecordSource(ObservableCollection 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.

Replies

Know the answer? Post it — somebody with the same question will find it here.