0
votes

I have a user control that contains button as follows

<UserControl x:Class="MyNamespace.myuseercontrol>
<Button Name="uxRemove" Grid.Row="2" Grid.Column="5" VerticalAlignment="Center"    
        HorizontalAlignment="Right" Width="70" Content="Remove"
        Click="uxRemove_Click"/> 
</UserControl>

the main window is as follows:

<Window>
<stackpanel>
    <local:MyUserControl x:Name="uxPanel1" />
</stackpanel>
</Window>

Requirements:

  1. I'd like to fire an event on the parent window when the event uxRemove_Click is fired at the usercontrl.
  2. I'd like to add property Isenabled to the stackpanel "Usercontrol container" that will be based upon My usercontrol.IsEnabled property.
1
I found a good solution Here. are there any better solution? - sayed saad

1 Answers

2
votes

The MDI-style solution may be a bit overcomplicated for what you are doing.

There is an example of raising events from child controls to a parent window here.

This is the basic gist:

  • Declare a custom event type and a way to register handlers
  • Raise the event in the child control wherever you need to
  • Have a handler on the parent window that listens for the event

This is a much simpler solution for you than implementing an MDI style WPF application.