Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

My WPF Paging Custom Control Not Working

$
0
0

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.

Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>