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 8379473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:11:48+00:00 2026-06-09T16:11:48+00:00

I am Silverlight newbie and I can’t make the simple Silverlight binding sample work!

  • 0

I am Silverlight newbie and I can’t make the simple Silverlight binding sample work!

I need to make a view-model, that shows the number of documents in the list, while it is loading.

I made a base-class, that implements INotifyPropertyChanged:

public abstract class BaseViewModel : INotifyPropertyChanged {

    protected BaseViewModel() {}


    #region INotifyPropertyChanged Members

    protected void OnPropertyChanged(string propertyName) {
        PropertyChangedEventHandler handler = PropertyChanged;

        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    #endregion
}

I made a child-class, that has “CountDocs” property:

public class DocumentViewModel : BaseViewModel {

    public DocumentViewModel () {
    ...
    }

...

    public int CountDocs {
        get { return countDocs; }
        set {
            if (countDocs != value) {
                countDocs = value;
                OnPropertyChanged("CountDocs");
            }
        }
    }

    public int countDocs;

}

I have DocumentViewModel.xaml with the following contents:

<UserControl 
...
xmlns:vm="clr-namespace: ... .ViewModels" >
...
<UserControl.Resources>
    <vm:DocumentViewModel  x:Key="viewModel"/>
</UserControl.Resources>
...
<TextBlock x:Name="CounterTextBlock" Text="{Binding Source={StaticResource viewModel}, Path=CountDocs}"></TextBlock>

That is I mentioned namespace of my child-class, I made a resource of my child class with key “viewModel”, and I entered binding of textblock, to this object’s property “CountDocs”.

The problem is that the CountDocs property fills the TextBlock only once: on load. But then I set CountDocs, and it does not fill the TextBlock.

I have tried to use the Mode property of binding, to use DataContext, but I still can’t make it work.

Is there something wrong with the binding? How to make the ViewModel update when the CountDocs property of my object is changed?

Thanks

  • 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-06-09T16:11:50+00:00Added an answer on June 9, 2026 at 4:11 pm

    Ok since you created your ViewModel instance in your XAML, you’ll need to access and use that ViewModel.

    If you have another instance, that instance won’t update your binding. Only the instance created in your Resources would be used.

    Now you said you set the CountDocs property but I don’t see any code for that. Whereever you do that, you have to use the ViewModel instance from your Resources.

    This is why I like to instantiate my view model in my constructor of my view and keep a reference to it. Also unless you plan to have many data sources attached to your bindings, you can simply set the LayoutRoot.DataContext to you ViewModel instance and remove the Source attribute in your binding.

    ViewModelBase _vm = null;
    public MyView()

    {
    _vm = new DocumentViewModel();
    this.LayoutRoot.DataContext = _vm;
    }

    In XAML,
    <TextBlock x:Name="CounterTextBlock" Text="{Binding CountDocs}"></TextBlock>

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

Sidebar

Related Questions

Can Silverlight 3 OPEN SOCKETS? If yes. What do I need MSDN if there
I'm sure that this is a simple newbie question, but the answer is eluding
I'm trying to make a simple Windows Phone 7 Silverlight app. There's the MainPage.xaml
In Silverlight, how can I test in a simple if/then if a RadioButton is
Silverlight newbie question: I've got a small Silverlight application with the following XAML snippet:
Silverlight experts out there, I need some help. I used Deep Zoom Composer to
In Silverlight, how can I stretch the width of a Line to fill the
Can Silverlight play video with transparency ? At least some tricky way for color
I'm a Silverlight newbie. Just downloaded version 3.0 after the Mix announcement. I'm running
I've been trying to find a good advanced Silverlight 4 course, but can't really

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.