How do I pass a xaml element as a property?

Russ Suter
Russ Suter used Ask the Experts™
on
I'm still learning the mechanics of this whole WPF thing. I'm creating a user control. One of the things I want my control to be able to do is respond to click events of a control on the parent window. To do this, I have created a property called "Activator" like this:
		public DependencyObject Activator { get; set; }
		public static readonly DependencyProperty ActivatorProperty = DependencyProperty.Register("Activator", typeof(DependencyObject), typeof(NavView));

Open in new window

I then markup my Xaml like this:
                <Button Name="buttonShowHideMyControl" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Right" Style="{DynamicResource HeaderButton}" Grid.ColumnSpan="2" Margin="0,4,9,0">
                    <fa:FontAwesome Grid.Column="2" Icon="Bars" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="White" FontSize="24" Margin="10,4,0,4"/>
                </Button>
            <local:TestUserControl x:Name="testUC" Grid.Column="1" HorizontalAlignment="Right" Visibility="Hidden" Opacity="0" Activator="{Binding Property, ElementName=buttonShowHideMyControl}">
                
            </local:TestUserControl>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014
Commented:
If you don't bind to a specific property, the Button is the value passed to your Activator property.
Activator="{Binding ElementName=buttonShowHideMyControl}"

Open in new window

Russ SuterSenior Software Developer

Author

Commented:
Perfect. Works like a charm now. Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial