Binding properties in code behind

Posted by drasto on Stack Overflow See other posts from Stack Overflow or by drasto
Published on 2010-05-30T12:42:55Z Indexed on 2010/05/30 12:52 UTC
Read the original article Hit count: 321

Filed under:
|
|
|

I have WPF application and a window in it. Lets have something like this in my xml:

<Label Name="TitleLabel" Content="Some title" \>
<Label Name="BottomLabel" Content="{Binding ElementName=TitleLabel Path=Content">

Lets say I don't cannot use xml for creation of BottomLabel and TitleLabel. So I have to create the BottomLabel as a property in my "Code behind". How do I specify the same binding for Content property of Bottom label in my code behind ? Is it possible at all ?

So I would have something like this:

public Label TitleLabel {get; private set;}
public Label BottomLabel {get; private set;}

public MyClass(){
    TitleLabel = new Label();
    TitleLabel.Content = "Some title";
    BottomLabel = new Label();
    BottomLabel.Content = // ?? what should be here ? How do I specify the binding
                          // that binds BottomLabel.COntent to TitleLabel.Content?
}

What can I write instead of the comment ? Thank you for ansvers.

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf