Databinding to Classmember of Classmember

Posted by Walter on Stack Overflow See other posts from Stack Overflow or by Walter
Published on 2010-06-16T07:17:47Z Indexed on 2010/06/16 7:22 UTC
Read the original article Hit count: 343

Filed under:
|
|

Hello,

I need some help about WPF and Databinding.

Let's say I have a ClassA with a member of ClassB. ClassB has again a member, maybe an int:

ClassB
{
  public int MemberOfB { get; set; }
}

ClassA
{
    private ClassB _theB;
    public ClassB MemberOfA
    {
        get {return _theB;}
        set
        {
            _theB = value;

            // Need to do something here...
        }
    }
}

When I have a Databinding in XAML like this:

<TextBox Text="{Binding Path=MemberOfA.MemberOfB}"/>

Where the Datacontext of the Textbox is an object of type ClassA.

As you can see, i need to do some computations in the setter of MemberOfA in ClassA. But with the databinding above, this setter is of course never called, because it binds to the member of ClassB.

So, how can i get to be informed if the MemberOfA changes (when I Type something into the Textbox)? Are there any best practices? (Didn't check the code in Visual Studio, so there may be some syntax errors).

Thanks, Walter

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf