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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:48:49+00:00 2026-05-27T21:48:49+00:00

Cant get any data to work with databinding, I have the INotify event, I

  • 0

Cant get any data to work with databinding, I have the INotify event, I have the binding on the xaml objects, but nothing shows up, if I change the content on the lables to “something” it works, but nothing shows on load or on click on my button

My Xaml view

<Grid>
    <StackPanel Name="stackpanel">
        <Label Content="{Binding Name}" />
        <Label Content="{Binding Length}" />
        <Label Content="{Binding Rating}" />
        <Button Content="Change text" Click="ButtonClick" />
    </StackPanel>
</Grid>

Its codebehind

public partial class Movie
{
    readonly MovieViewModel _movieViewModel;

    public Movie()
    {
        InitializeComponent();
        _movieViewModel = new MovieViewModel { Movie = { Name = "The Dark Knight", Length = 180, Rating = 88 } };
        stackpanel.DataContext = _movieViewModel;
    }

    private void ButtonClick(object sender, RoutedEventArgs e)
    {
        _movieViewModel.Movie.Name = "bad movie";
    }
}

The View Model

class MovieViewModel
{
    public MovieViewModel() : this(new Movie())
    {
    }

    public MovieViewModel(Movie movie)
    {
        Movie = movie;
    }

    public Movie Movie { get; set; } 
}

The Model

class Movie : INotifyPropertyChanged
{
    public Movie()
    {}

    private string _name;
    public string Name
    {
        get { return _name; }
        set
        {
            _name = value;
            NotifyPropertyChanged("Name");
        }
    }

    private int _length;
    public int Length
    {
        get { return _length; }
        set 
        { 
            _length = value;
            NotifyPropertyChanged("Length");
        }
    }

    private int _rating;
    public int Rating
    {
        get { return _rating; }

        set
        {
            if (_rating == value) return;
            _rating = value;
            NotifyPropertyChanged("_Rating");
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    public void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
  • 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-27T21:48:50+00:00Added an answer on May 27, 2026 at 9:48 pm

    You have your bindings set incorrectly, that’s the reason nothing is being shown.

    Just take a closer look at your ViewModel and than on the bindings. You try to bind to property named Name but your MovieViewModel does not expose any property with that name. I’m pretty sure binding errors were reported to you (look through messages in Output window).

    To make it work, you need either expose properties in your ViewModel to match the ones you try to bind to (bad), or change bindings in your xaml to have correct path:

    <Label Content="{Binding Movie.Name}" />
    <Label Content="{Binding Movie.Length}" />
    <Label Content="{Binding Movie.Rating}" />
    

    This should get you going.

    Additionally – you may want to implement INotifyPropertyChanged also on your MovieViewModel class if you plan to change Movie object that is assigned to Movie property. As long as you will only change properties of Movie object already assigned to MovieViewModel everything will be ok, but if you would try to change actual object assigned to this property, no changes notifications will be generated and your UI will stop working correctly.

    Moreover – I noticed that you made your NotifyPorpertyChanged method public – I wouldn’t advise this as anyone can now trigger this event. Normal approach is to make such methods private or protected, depending if you want to provide way to trigger event from inheriting classes (which is very likely in case of PropertyChanged event).

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

Sidebar

Related Questions

I'm probably doing something realy stupid but I cant get this to work: var
Im using JSON.NET do deserlaize an object, but i cant get it to work
I am trying to populate a combo box with data but I cant get
Searched and searched for some guidance but cant seem to get anything to work.
I cant figure out how to get lua to do any common timing tricks,
i have againg a problem with completition. now i can't get any suggestion. Sure
I'm doing in-line edits on a grid, but can't seem to get any events
I can't get DDMS to load any KML files. I have a KML file
I can't get my progress bar to work. Any help is much appreciated! Here's
with $element->children() i cant get all the child elements of current element. but how

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.