Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6234457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:29:21+00:00 2026-05-24T10:29:21+00:00

I know this topic has been discussed, but not by me yet. As I

  • 0

I know this topic has been discussed, but not by me yet. As I have seen on other examples about this issue, I am trying to create some basic custom DataPager UserControl. So that I did the following :

XAML:

 <ComboBox Name="Size"  ItemsSource="{Binding PageSourceSize}"  
                      SelectedValue="{Binding PageSizePager}"  />

With the following C#:

ObservableCollection<int> _PageSourceSize;

public ObservableCollection<int> PageSourceSize
    {
        get { return _PageSourceSize; }
        set
        {
            _PageSourceSize = value;
            RaisePropertyChanged("PageSourceSize");
        }
    }

public MyDataPager()
{
     DataContext = this;
     PageSizePager = 10;
     PageSourceSize = new ObservableCollection<int>() { 10, 20, 50,100 };
}


public int PageSizePager
{
    get { return (int)GetValue(PageSizePagerProperty); }
    set { SetValue(PageSizePagerProperty, value); }
}

public static readonly DependencyProperty PageSizePagerProperty =
    DependencyProperty.Register("PageSizePager", typeof(int), typeof(MyDataPager), new PropertyMetadata(10));

From here I intend to use my pager in a main UserControl :

 <local:MyDataPager  PageSizePager="20" x:Name="MyDataPager1" />

This works fine, but I would have liked to get the value from my viewModel using:

<local:MyDataPager  PageSizePager="{Binding Path=PageSize,Mode=TwoWay}" x:Name="MyDataPager1" />

And the view model:

public int PageSize
{
  get { return (int)GetValue(PageSizeProperty); }
  set { SetValue(PageSizeProperty, value); }
}

public static readonly DependencyProperty PageSizeProperty =
            DependencyProperty.Register("PageSize", typeof(int), typeof(ViewSchedeConsuntiviViewModel), new PropertyMetadata(10));


public MyViewModel()
{
  PageIndex = 1;
  PageSize = 20;
}

Could someone explain me why the binding between the view model and the user control does not work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:29:22+00:00Added an answer on May 24, 2026 at 10:29 am

    Working with a colleague of mine, we found a solution for what I intended to do :

    In the Xaml of the MyDataPager usercontrol :

    <Grid x:Name="LayoutRoot" Background="White" Loaded="MyDataPager_Loaded">
    ....
    

    going with this definition of MyDataPager_Loaded :

    void MyDataPager_Loaded(object sender, RoutedEventArgs e)
            {
                ((Grid)sender).DataContext = this;
            }
    

    From the code above we have changed the ctor of the MyDataPager usercontrol to remove the datacontext binding :

    public MyDataPager()
            {
                //DataContext = this;
    

    Working this way, I am able to bind values in the main usercontrol like this :

    <local:MyDataPager  PageSizePager="{Binding Path=PageSize,Mode=TwoWay}" x:Name="MyDataPager1" />
    

    So that the binding is made upon properties of the childusercontrol, not upon its control(ie: look of the child control may change without problems), and so that the child usercontrol does not have to use any “known” values from the datacontext of the main usercontrol.

    Thanks for reading and for your support, it was greatly welcomed.I Hope these lines might serve another one in need of this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this has been a hot topic over the time... but I can't
I know this is a popular topic, but I've been searching quite a bit
I know this isn't strictly a programming question but y'all must have experienced this.
I know this is not programming directly, but it's regarding a development workstation I'm
I know this might be a no-brainer, but please read on. I also know
I know this is a broad question, but I've inherited several poor performers and
I know this site is written using ASP.Net MVC and I do not see
I know this rather goes against the idea of enums, but is it possible
I know this would be easy with position:fixed, but unfortanately I'm stuck with supporting
I know this is a long shot - but is there any way at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.