ygoe
ygoe

Reputation: 20414

Pass another control as property value in XAML

Consider a XAML snippet like this:

<Grid>
    <Button x:Name="myButton"/>
    <m:MyControl Button="myButton"/>
</Grid>

Of course this doesn't work. But what I need is to pass the Button control instance named "myButton" as value to the other control's Button property. I've also tried it with {StaticResource myButton} but it fails telling me that the resource cannot be found.

What's the correct XAML syntax for that?

Upvotes: 1

Views: 450

Answers (1)

LPL
LPL

Reputation: 17083

If MyControl.Button is a DependencyProperty you can do it so

<m:MyControl Button="{Binding ElementName=myButton}" />

Upvotes: 2

Related Questions