Page with a DataGrid, a modal dialog for add/edit operations, and registration in the main menu. Follow these steps to add a new module.
This guide uses Equipos (equipment) as a concrete example.
Create the data model class
Declare a plain C# class for your entity inside the page’s code-behind file. All properties are strings unless the field is inherently boolean (like a connection state).
Create the Page XAML
Add a new WPF Page to the project: right-click the project in Solution Explorer → Add → New Item → Page (WPF) → name it
Equipos.xaml.Structure the page with a search filter TextBox at the top, a DataGrid bound to your collection, and Add / Edit / Delete buttons:Create the Page code-behind
Implement the page class with:
- An
ObservableCollection<EquipoItem>field. - A
CargarDatosDePrueba()method called from the constructor. - Click handlers for Add, Edit, and Delete.
- A
TextChangedhandler for the search filter.
ObservableCollection<T> automatically notifies the DataGrid when items are added or removed, so you do not need to manually refresh ItemsSource after each operation.Create the modal dialog
Add a new WPF Window: Add → New Item → Window (WPF) → name it
AgregarEquipoWindow.xaml.The dialog exposes a NuevoEquipo property that the page reads after ShowDialog() returns:Register the menu item in MenuPrincipal.xaml
Open
MenuPrincipal.xaml and add a Border menu item inside the sidebar StackPanel, following the same structure as existing items. Each item contains an icon Path and a TextBlock label:The
TextBlock label is hidden when the sidebar collapses to 60 px because its parent StackPanel clips to the sidebar width. Only the Path icon remains visible in collapsed state.Register the click handler in MenuPrincipal.xaml.cs
Open After completing this step, build and run the application. Your new Equipos menu item should appear in the sidebar, navigate to the page when clicked, and support adding, editing, deleting, and filtering records.
MenuPrincipal.xaml.cs and add a handler for the new menu item. Call FrameSecundario.Navigate() with a new page instance and pass the clicked Border to ActualizarSeleccion():Menu click handlers use
MouseButtonEventArgs (not RoutedEventArgs) because sidebar items use MouseLeftButtonUp events, not WPF Button.Click events. Pass the named border element directly to ActualizarSeleccion — do not use sender.ActualizarSeleccion resets all menu item backgrounds to their default color, applies the #678EC2 highlight to the selected item, and collapses the sidebar to 60 px:Summary of files created
| File | Type | Purpose |
|---|---|---|
Equipos.xaml | WPF Page | DataGrid view with search filter and action buttons |
Equipos.xaml.cs | Code-behind | EquipoItem model, collection, and CRUD handlers |
AgregarEquipoWindow.xaml | WPF Window | Add / Edit modal dialog form |
AgregarEquipoWindow.xaml.cs | Code-behind | NuevoEquipo property and save handler |
| File | Change |
|---|---|
MenuPrincipal.xaml | Add a Border sidebar item |
MenuPrincipal.xaml.cs | Add Menu_Equipos_Click handler |