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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:06:55+00:00 2026-05-31T13:06:55+00:00

I am creating an application that uses several threads as a result I want

  • 0

I am creating an application that uses several threads as a result I want to try to use UIControls in my code behind as few as possible. The way I do it is by binding the controls to a property in my code behind that way I will be able to update the control by changing that property it does not matter if that property is updated on a different thread. Anyways I am creating the following code in order for the class to create the bindings form me.

public static class MyExtensionMethods 
{

    public static TextBoxBind<T> BindTextBox<T>(this TextBox textbox, string property=null)
    {
        return new TextBoxBind<T>(textbox,property);
    }
}



public class TextBoxBind<T> : INotifyPropertyChanged
{
    string property;

    protected T _Value;
    public T Value
    {
        get { return _Value; }
        set { _Value = value; OnPropertyChanged(property); }
    }

    public event PropertyChangedEventHandler PropertyChanged = delegate { };
    protected void OnPropertyChanged(string propertyName){
        PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }

    public TextBoxBind(TextBox textbox, string property)
    {
        if (property == null)
        {
            property = "Value";
        }
        this.property = property;

        Binding b = new Binding(property)
       {
            Source = this
       };

        b.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
        textbox.SetBinding(TextBox.TextProperty, b);
    }
}

And on my XAML I have:

 <TextBox  Name="textBox2"  />

Therefore I will be able to use the first code that I posted as:

        var newTextBox2 = textBox2.BindTextBox<int>();
        newTextBox2.Value = 50; // this will update the textBox2.Text = "2"
        // also every time I update the value of textBox2  newTextBox2.Value will update as well

The problem is when I try to bind it to a custom object. Take this code for example:

    public class Person 
    {
        public string Name { get; set; }
        public string Age { get; set; }

        public override string ToString()
        {
            return Age.ToString();
        }            

    }

    void LogIn_Loaded(object sender, RoutedEventArgs e)
    {
        txtUsuario.Focus();

        var newTextBox2 = textBox2.BindTextBox<Person>("Age");

        // here newTextBox2 never updates....


    }
  • 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-31T13:06:56+00:00Added an answer on May 31, 2026 at 1:06 pm

    OnPropertyChanged(property); should be pointing to Value, since that’s the Name of your Property.
    This should not be pointing to the type T.
    So this code is not right:

    if (property == null) 
    { 
      property = "Value"; 
    }
    

    because property should always be "Value"

    public T Value     
    {     
        get { return _Value; }     
        set { _Value = value; OnPropertyChanged("Value"); }     
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to open-source an application that uses API keys I'm creating an
I'm creating an application that uses an ImageSwitcher to show some images. I want
I am creating an application that uses popups. However, I would like to animate
I am creating an ASP script that uses the application object to store the
I'm creating an console application which needs to run several threads in order to
I am creating C# application that uses OCX component. I have this component from
I'm creating an application that uses amazon s3 for storage in C#. It may
I am creating a mapping application that uses a WSGI service and needs a
I’m creating an application that uses Core Data to store information and uses web
I am creating an application in Flex that uses an embedded SQLite database. The

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.