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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:56:40+00:00 2026-05-25T19:56:40+00:00

I want to bind a TextBox in the window to a property contained within

  • 0

I want to bind a TextBox in the window to a property contained within a class that is a variable of the viewmodel and ensure that INotifyPropertyChanged’s PropertyChanged event propagates from the class to the parent.

Let me illustrate with an example:

(Window’s DataContext is set to an instance of ViewModel)

public class ViewModel {
    private OtherClass classInstance = new OtherClass();

    public int Attribute {
        get { return classInstance.Attribute; }
    }
}

public class OtherClass : INotifyPropertyChanged {
    private int _attribute;
    public int Attribute {
        get { return _attribute; }
        set { 
            _attribute = value;
            PropertyChanged("Attribute");
        }
    }
    ...
}

The problem in this example is that, when Attribute changes, the bound Textbox does not update the binding since I assume it’s listening to the ViewModel’s PropertyChanged event and not that of the instance of OtherClass.

Any ideas on how to remedy this situation? I was thinking about chaining OtherClass’s INotifyPropertyChanged to that of its parent, but there has to be a better way.

  • 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-25T19:56:41+00:00Added an answer on May 25, 2026 at 7:56 pm

    Why not bind directly to the class property instead of using a proxy?

    public class ViewModel {
        private OtherClass classInstance = new OtherClass();
    
        public OtherClass MyOtherClass {
            get { return classInstance; }
        }
    }
    

    Then in your binding you can simply reference the property via the SubClass

    {Binding MyOtherClass.Attribute}
    

    A drop dead simple example, but it works!

    The Code Behind:

    public partial class MainWindow : Window {
       private readonly SomeClass _someClass = new SomeClass();
    
       public MainWindow() {
          InitializeComponent();
          DataContext = _someClass;
       }
    }
    
    public class SomeClass: INotifyPropertyChanged {      
       private readonly SomeSubClass _mySubClass = new SomeSubClass();
    
       public SomeSubClass MySubClass {
          get { return _mySubClass; }
       }
    
       private String _name;
       public String Name {
          get { return _name; }
          set {
             _name = value;
             OnPropertyChanged("Name");
          }
       }
    
       //Property Change Stuff
    }
    
    public class SomeSubClass : INotifyPropertyChanged {
       private String _name;
       public String Name {
          get {
             return _name;
          }
          set {
             _name = value;
             OnPropertyChanged("Name");
          }
       }
    
       //Property Change Stuff
    }
    

    The XAML:

    <Window x:Class="JWC.Examples.WPF.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow">
        <StackPanel>
            <Label Content="Name" VerticalAlignment="Top" />
            <TextBox Text="{Binding Name}" />
            <Label Content="SubClass.Name" />
            <TextBox Text="{Binding MySubClass.Name}" />
            <Label Content="Bound to Name" />
            <TextBlock Text="{Binding Name}" />
            <Label Content="Bound to MySubClass.Name" />
            <TextBlock Text="{Binding MySubClass.Name}" />
        </StackPanel>
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to bind an event to a certain class and ID for when
I have a textbox I want to bind to DateTime property to an object
I want to bind a property object to a textBox, but the value is
I want to bind TextBox's Text property to FolderBrowser's SelectedPath property. But it's not
i have an input element, and i want bind both change and keypress event
I want to bind one property to multiple sources. My reason for this are
I want to bind a click event with the element: $('a').click(function(){ btn_submit_pressed=false; }); Now,
Normally we bind a textbox's Text property to a data-context's properties. The data-context can
I want to bind a controls visibility to inverse of boolean property value. I
I want to implement that when a textbox value is changed, my Add button

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.