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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:06:42+00:00 2026-05-21T22:06:42+00:00

My goal is to bind to a set of objects in WPF. I first

  • 0

My goal is to bind to a set of objects in WPF. I first tried to use generics but horribly failed at it. Since I can’t cast generic properties to INotifyProperty interfaces, to hook up the changedevent.

So I came up with this class to use as an object in my BindingList. ( Yes, I need those to notify me when an object within the list changes ). So I need your opinion, improvements on my code.

public class GPair : ObservableObject
{
    public GPair()
    {
    }

    private ObservableObject _first;
    public ObservableObject First
    {
        get
        {
            return this._first;
        }
        set
        {
            this._first = value;
            ((ObservableObject)value).PropertyChanged +=new PropertyChangedEventHandler(First_PropertyChanged);
            RaisePropertyChanged("First");
        }
    }
    private ObservableObject _second;
    public ObservableObject Second
    {
        get
        {
            return this._second;
        }
        set
        {
            this._second = value;
            ((ObservableObject)value).PropertyChanged += new PropertyChangedEventHandler(Second_PropertyChanged);
            RaisePropertyChanged("Second");
        }
    }

    private void First_PropertyChanged(object sender, PropertyChangedEventArgs args)
    {
        RaisePropertyChanged("First");
    }
    private void Second_PropertyChanged(object sender, PropertyChangedEventArgs args)
    {
        RaisePropertyChanged("Second");
    }
}

The ObservableObject is just a helperclass that implements the INotifyPropertyChanged.

This piece of code allows me couple two objects in a binding… The Binding itself would look like this:

<StackPanel Orientation="Horizontal">
    <TextBlock Text="{Binding Path=First.ObjectPropertie}" />
    <TextBlock Text="{Binding Path=Second.ObjectPropertie}" />
</StackPanel>

Any opinions or improvements??

Kind regards!

  • 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-21T22:06:43+00:00Added an answer on May 21, 2026 at 10:06 pm

    I don’t fully get what you are trying to achieve, but the GPair class looks odd

    What about having something like this?

      public class ObservablePair : INotifyPropertyChanged
      {
            public event PropertyChangedEventHandler PropertyChanged;
    
            private MyObject m_First;
            public MyObject First
            {
                get { return m_First; }
                set
                {
                    m_First = value;
                    OnPropertyChanged("First");
                }
    
            }
    
            private MyObject m_Second;
            public MyObject Second
            {
                get { return m_Second; }
                set
                {
                    m_Second = value;
                    OnPropertyChanged("Second");
                }
            }
    
            public void OnPropertyChanged(string propertyName)
            {
                    PropertyChangedEventHandler handler = PropertyChanged;
                    if (handler != null) handler(this, new 
                        PropertyChangedEventArgs(propertyName)); ;
            }
     }
    

    HTH

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

Sidebar

Related Questions

My goal is to add different Controls/UserControls in a WPF ListView. The Controls can
I have the following code: var GoalPanelView = Backbone.View.extend({ // Bind to the goal
goal: I have the string 1234432144 I want to only replace the first 2
Goal To use a CREATE TYPE statement in HSQLDB 2.0.0 to create a user-defined
http://jsfiddle.net/AYPze/9/ In this example I have two similar divs with the same goal. Bind
This is related to a similar question about BIND, but in this case I'm
In perl DBI , you can bind a hash element value to a specific
Trying to build a mavenized project with NetBeans fails: Failed to execute goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.7.5:generate
I would like to Bind() a TextBox in an EditItemTemplate but I need to
I tried using the boost deadline_timer in this simple test application, but had some

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.