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

  • SEARCH
  • Home
  • 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 6895225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:52:53+00:00 2026-05-27T06:52:53+00:00

Most likely I am doing the databinding for my UserControl in a wrong manner,

  • 0

Most likely I am doing the databinding for my UserControl in a wrong manner, please point me to an error.

I have a UserControl decleared in XAML of my page view (view.xaml):

<StackPanel Grid.Row="1" Margin="0,20,0,0" x:Name="ProgressBarPanel" HorizontalAlignment="Center">
                <deusControls:BookProgressBar BookProgressValue="{Binding BookProgressInfo, Mode=OneWay}" Width="430" />
            </StackPanel>

The control itself is simply a wrapped listbox (myprogressbar.xaml):

<Grid x:Name="ProgressBarLayoutRoot">

        <ListBox x:Name="ProgressBarControl" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding Bars, RelativeSource=this}">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Border Height="15" BorderThickness="1" CornerRadius="{Binding Corner}" Width="{Binding Width}" Background="{Binding IsAchieved, Converter={StaticResource progressToColor}}"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

    </Grid>

The BookProgressValue is registered in a control’s code behind as a dependency property:

public BookProgressInfo BookProgressValue {
            get { return (BookProgressInfo)GetValue(BookProgressValueProperty); }
            set { SetValue(BookProgressValueProperty, value); }
        }

        public static readonly DependencyProperty BookProgressValueProperty =
            DependencyProperty.Register("BookProgressValue", typeof(BookProgressInfo), typeof(BookProgressBar), 
            new PropertyMetadata(new BookProgressInfo(0), new PropertyChangedCallback(BookProgressValueChanged)));

        static void BookProgressValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var bookProgressBar = (BookProgressBar)sender;

            var progressInfo = (BookProgressInfo) e.NewValue;

            if(progressInfo != null && progressInfo.Id != 0) 
                bookProgressBar.DataContext = new BookProgressBarViewModel(progressInfo, bookProgressBar.Width);
        }

The BookProgressValue="{Binding BookProgressInfo, Mode=OneWay}" should be binding to a BookProgressInfo property in the views view model.

The view model recieves a new data from the logic to put forward to UI as a value of BookProgressInfoproperty, and calls a NotifyPropertyChanged("BookProgressInfo");

At this point I am expecting my control to process BookProgressValueChanged event to update the control’s own data context (basically to get an updated set of Bars that it binds to.) but the BookProgressValueChanged is not raised after NotifyPropertyChanged.

Main question is:
What is the correct way of getting a view to have one DataContext, whereas a UserControl that is placed inside a view – to have it’s own, base on a value to a dependecy property set through databinging?

Please let me know if the explanation of the question is unclear, I will improve. Thank you.

  • 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-27T06:52:54+00:00Added an answer on May 27, 2026 at 6:52 am

    I think that you should add to root grid this line:

    <Grid x:Name="ProgressBarLayoutRoot" 
          DataContext="{Binding ElementName=userControl, BookProgressValue}"
    

    And also add name to your UserControl:

    <UserControl x:Name="userControl" 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is driving me crazy and most likely I am doing this wrong. So
We have decided to work with the Insert Framework Here We'll most likely update
I am new to Google Maps, so I have most likely missed something very
I have a list of string, which is most likely, but not guaranteed to
With LINQ to SQL most likely going to not get as much active development
This is most likely not an easy one but here is the situation: I
I know this is most-likely a simple question but when you restore a database
I need to implement a browser based component (most likely java applet since it
I know $_SERVER['DOCUMENT_ROOT'] returns the document root (most likely something like /home/user/public_html), but is
I'm looking for a non-linear curve fitting routine (probably most likely to be found

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.