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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:06:53+00:00 2026-06-07T06:06:53+00:00

For an application I have to use a custom button that react when one

  • 0

For an application I have to use a custom button that react when one of its properties value is being changed. I addded a field named Data to the new button:

public class ButtonData
{
    public string Name;
    public string Color;
    //And more stuff...
}

Then I have the folowing code for new button, I want it to be able to update itself (change background color and some other stuff) whenever its Data property gets updated from somewhere in application. I found some ideas about implementing INotifyPropertyChanged interface and I set it up in my custom button like this:

public partial class ButtonPin : Button, INotifyPropertyChanged
{
    private ButtonData _data;

    public ButtonData Data
    {
        get { return _data; }
        set
        {
            if (value == _data) return;
            _data = value;
            OnPropertyChanged("Data");
        }
    }
    private bool _buttonDataAdded;


    public ButtonPin()
    {
        InitializeComponent();
    }

    public ButtonPin(ButtonData data)
    {
        Data = data;
        _buttonDataAdded = true;
    }

    public event PropertyChangedEventHandler PropertyChanged;

    public void OnPropertyChanged(string propertyName)
    {
        var handler = PropertyChanged;
        if (handler != null)
            handler(this, new PropertyChangedEventArgs(propertyName));
    }
  }

Now I am not sure how to use this! For example, if the Color in Data objects gets changed
somehow somewhere and its get assigned to current button’s Data field, I want this button to change its background color. Something like

var data = new ButtonData();
data.Name = "Hi!";
data.Color = Color.Red;

buttonPin1.Data = data; //Here I need the changes to occur
  • 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-07T06:06:54+00:00Added an answer on June 7, 2026 at 6:06 am

    You have implemented the interface INotifyPropertyChanged on the ButtonPin class, not on the ButtonData class, and you want to detect a change on an object of type ButtonData, thus you need to implement the interface INotifyPropertyChanged on the ButtonData class.

    To detect the change you need to hook up to the PropertyChanged event of the ButtonData object in the setter of the ButtonPin.Data property. Something like this.

    private bool _data;
    public ButtonData Data {
        get { return _data; }
        set {
            if (value != _data) {
                // Unhook previous events
                if (_data != null)
                    _data.PropertyChanged -= HandleButtonDataPropertyChanged;
                // Set private field
                _data = value;
                // Hook new events
                if (_data != null)
                    _data.PropertyChanged += HandleButtonDataPropertyChanged;
                // Immediate update  since we have a new ButtonData object
                if (_data != null)
                    Update();
            }
        }
    }
    
    private void HandleButtonDataPropertyChanged(object sender, PropertyChangedEventArgs e) {
        // Handle change in ButtonData
        Update();
    }
    
    private void Update() {
        // Update...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Android application I have to use common string value for all activities.
I have an external (.Net) dll that I have to use for an application.
I have C# application that makes use of some C libaries(which I have written
What I have is a class with static properties that I want to use
I am creating an asp web application that can't use JQuery and uses custom
We have common views that we use in our application in many locations inside
I have the following post button that i use for paypal transactions: <form action=https://www.sandbox.paypal.com/cgi-bin/webscr
I have created a custom UIView that I would like to use on multiple
I have a button in my obj-c application that I would like to launch
I have this application that uses custom methods to register and loggin users using

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.