Link to home
Start Free TrialLog in
Avatar of Russ Suter
Russ Suter

asked on

How do I pass a xaml element as a property?

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

ASKER CERTIFIED SOLUTION
Avatar of louisfr
louisfr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Russ Suter
Russ Suter

ASKER

Perfect. Works like a charm now. Thanks!