Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
swdev:dotnet:wpf:user_controls_and_intercommunication [2010/09/30 16:34] smayr |
swdev:dotnet:wpf:user_controls_and_intercommunication [2011/05/25 09:48] (current) smayr |
||
---|---|---|---|
Line 2: | Line 2: | ||
For applications that are composed of multiple user controls, there needs to be coordination and communication between them. For example, an application' | For applications that are composed of multiple user controls, there needs to be coordination and communication between them. For example, an application' | ||
+ | <code xml> | ||
+ | <Window x: | ||
+ | xmlns=" | ||
+ | xmlns: | ||
+ | xmlns: | ||
+ | Title=" | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Attach menu event programmatically (in C#): | ||
+ | <code csharp> | ||
+ | using System; | ||
+ | using System.Collections.Generic; | ||
+ | using System.Linq; | ||
+ | using System.Text; | ||
+ | using System.Windows; | ||
+ | using System.Windows.Controls; | ||
+ | using System.Windows.Data; | ||
+ | using System.Windows.Documents; | ||
+ | using System.Windows.Input; | ||
+ | using System.Windows.Media; | ||
+ | using System.Windows.Media.Imaging; | ||
+ | using System.Windows.Navigation; | ||
+ | using System.Windows.Shapes; | ||
+ | |||
+ | namespace InterUsrCtrlComm | ||
+ | { | ||
+ | /// < | ||
+ | /// Interaction logic for MainWindow.xaml | ||
+ | /// </ | ||
+ | public partial class MainWindow : Window | ||
+ | { | ||
+ | public MainWindow() | ||
+ | { | ||
+ | InitializeComponent(); | ||
+ | | ||
+ | // Attach menu event handler | ||
+ | popupmnu1.MenuItemSelected += new RoutedEventHandler(ucPopupMnu_MenuItemSelected); | ||
+ | } | ||
+ | | ||
+ | /// < | ||
+ | /// Event handler for Menu Item Selection in Popup menu. | ||
+ | /// </ | ||
+ | /// <param name=" | ||
+ | /// <param name=" | ||
+ | private void ucPopupMnu_MenuItemSelected(object sender, RoutedEventArgs e) | ||
+ | { | ||
+ | // Get menu selection | ||
+ | ListBoxItem selection = popupmnu1.SelectedItem; | ||
+ | |||
+ | // Take action based on the menu selection | ||
+ | content1.SelectedTabItem = selection.Content.ToString(); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | If the event is defined with XAML ('' | ||
<code xml> | <code xml> | ||
<Window x: | <Window x: | ||
Line 15: | Line 77: | ||
</ | </ | ||
- | '' | + | The code-behind looks like ('' |
<code csharp> | <code csharp> | ||
using System; | using System; | ||
Line 41: | Line 103: | ||
{ | { | ||
InitializeComponent(); | InitializeComponent(); | ||
+ | | ||
+ | // This next line should not be present, since XAML will add it automatically in InitializeComponent() | ||
+ | // | ||
} | } | ||
Line 251: | Line 316: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | == Resources == | ||
+ | * [[http:// | ||
+ | * [[http:// |