Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
swdev:dotnet:wpf:user_controls_and_intercommunication [2011/01/18 16:38]
smayr [Resources]
swdev:dotnet:wpf:user_controls_and_intercommunication [2011/05/25 09:48] (current)
smayr
Line 10: Line 10:
     <Grid>     <Grid>
         <local:ucContent x:Name="content1"/>         <local:ucContent x:Name="content1"/>
-        <local:ucPopupMnu x:Name="popupmnu1" MenuItemSelected="ucPopupMnu_MenuItemSelected"/>+        <local:ucPopupMnu x:Name="popupmnu1"/>
     </Grid>     </Grid>
 </Window> </Window>
 </code> </code>
  
-Or programmatically (in C#):+Attach menu event programmatically (in C#):
 <code csharp> <code csharp>
 using System; using System;
Line 42: Line 42:
             InitializeComponent();             InitializeComponent();
                  
 +            // Attach menu event handler
             popupmnu1.MenuItemSelected += new RoutedEventHandler(ucPopupMnu_MenuItemSelected);             popupmnu1.MenuItemSelected += new RoutedEventHandler(ucPopupMnu_MenuItemSelected);
         }         }
Line 62: Line 63:
 </code> </code>
  
-If defined with XAML, then the ''MainWindows.xaml.cs'' code-behind looks like:+If the event is defined with XAML (''MainWindows.xaml''), then: 
 +<code xml> 
 +<Window x:Class="InterUsrCtrlComm.MainWindow" 
 +        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
 +        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
 +        xmlns:local="clr-namespace:InterUsrCtrlComm" 
 +        Title="Inter User Control Communication" Height="350" Width="525"> 
 +    <Grid> 
 +        <local:ucContent x:Name="content1"/> 
 +        <local:ucPopupMnu x:Name="popupmnu1" MenuItemSelected="ucPopupMnu_MenuItemSelected"/> 
 +    </Grid> 
 +</Window> 
 +</code> 
 + 
 +The code-behind looks like (''MainWindows.xaml.cs''):
 <code csharp> <code csharp>
 using System; using System;
Line 88: Line 103:
         {         {
             InitializeComponent();             InitializeComponent();
 +            
 +            // This next line should not be present, since XAML will add it automatically in InitializeComponent()
 +            //popupmnu1.MenuItemSelected += new RoutedEventHandler(ucPopupMnu_MenuItemSelected);
         }         }