views:

177

answers:

2

Hi. Is there a way to bind to the instance of another control? Something like this:

<Button x:Name="Foo" Content="Foo" />
<local:CustomControl OtherControl="{Binding Foo}" />

I've tried setting DataContext to "this" in the constructor of MainPage but it doesn't seem to work.

CustomControl is defined something like this:

class CustomControl
{
    public FrameworkElement OtherControl { get; set; }
}
+1  A: 

It is impossible in Silverlight 2:

Silverlight 2 doesn’t allow you to bind one element to another element. Instead, all bindings are to data objects. (You could get around this using an intermediate object, but the added inconvenience means it’s rarely worthwhile.)

Dmytro Laptin
+4  A: 

Hi,

Not sure what you trying to do but in Silverlight 3 you can use element binding to bind to a property on a control.

<Button x:Name="Foo" Content="Foo" />
<local:CustomControl x:Name="control" Property="{Binding Path=Content, ElementName=Foo}" />

In code you could always analyze the binding and get the element from that?

control.GetBindingExpression(Property).ParentBinding.Source

afriend