In WPF I have created a form "Configuration.xaml" to enter the configuration values of my program. It contains a DevExpress "Hamburguermenu" control so that, when clicking on each menu option, different subforms appear, such as "Configuration_General.xaml", with the corresponding TextBox and ComboBox values.
The DevExpress "Hamburguermenu" control introduces the different menu options using the "MainViewModel.cs" system.
"Configuration.xaml" contains a "Save" button that starts the subform "configuracion_save.xaml" which is where there is a process that must collect the TextBox and ComboBox values from each subform in order to store them in a file.
The problem is, I don't know how to retrieve the TextBox and ComboBox values from each subform in order to save them.
configuracion.xaml
---------------------
MainViewModel.csCode:<dx:ThemedWindow x:Class="Name_MainWindow_Configuracion.MainWindow_Configuracion" xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:dxwui="http://schemas.devexpress.com/winfx/2008/xaml/windowsui" xmlns:dxwuin="http://schemas.devexpress.com/winfx/2008/xaml/windowsui/navigation" xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm" xmlns:local="clr-namespace:Name_MainWindow" mc:Ignorable="d" WindowStartupLocation="CenterScreen" Loaded="Fcn_OnWindowLoaded" Closing="Fcn_WindowClosing" Closed="Window_Closed" Title="Configuración" dx:ThemeManager.ThemeName="Office2016ColorfulSE" Width="850" Height="500"> <Window.DataContext> <local:MainViewModel/> </Window.DataContext> <Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="ItemTemplates.xaml"/> <ResourceDictionary> </ResourceDictionary> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Window.Resources> <dxwui:HamburgerMenu x:Name="Form_HamburgerMenu" AvailableViewStates = "Inline" Margin="0,0,2,0" OpenPaneWidth = "190" Visibility="Visible" ItemsSource = "{Binding HamburgerMenuItems}" BottomBarItemsSource = "{Binding HamburgerMenuBottomBarItems}" IsMenuVisible = "{Binding IsMenuVisible}" SelectedItem = "{Binding SelectedItem, Mode=TwoWay}" NavigationTarget = "{Binding ElementName=service}"> <dxwui:HamburgerMenu.Content> <dxwui:NavigationFrame> <dxmvvm:Interaction.Behaviors> <dxwuin:FrameNavigationService x:Name="service"/> </dxmvvm:Interaction.Behaviors> </dxwui:NavigationFrame> </dxwui:HamburgerMenu.Content> </dxwui:HamburgerMenu> </dx:ThemedWindow>
---------------------
Configuracion_General.xamlCode:namespace Name_MainWindow { public class MainViewModel : DevExpress.Mvvm.NavigationViewModelBase { public System.Collections.ObjectModel.ReadOnlyCollection<Name_MainWindow.IHamburgerMenuItemViewModel> HamburgerMenuItems { get; } public System.Collections.ObjectModel.ReadOnlyCollection<Name_MainWindow.IHamburgerMenuBottomBarItemViewModel> HamburgerMenuBottomBarItems { get; } public bool IsMenuVisible { get{ return GetProperty(() => IsMenuVisible); } set{ SetProperty(() => IsMenuVisible, value); } } public IHamburgerMenuItemViewModel SelectedItem { get{ return GetProperty(() => SelectedItem); } set{ SetProperty(() => SelectedItem, value, OnSelectedItemChanged); } } public MainViewModel() { HamburgerMenuItems = new System.Collections.ObjectModel.ReadOnlyCollection<Name_MainWindow.IHamburgerMenuItemViewModel>(InitializeMenuItems()); HamburgerMenuBottomBarItems = new System.Collections.ObjectModel.ReadOnlyCollection<Name_MainWindow.IHamburgerMenuBottomBarItemViewModel>(InitializeBottomBarItems()); SelectedItem = HamburgerMenuItems[0]; IsMenuVisible = true; } protected virtual System.Collections.Generic.IList<IHamburgerMenuItemViewModel> InitializeMenuItems() { string Mensaje = null; var IHamburgerMenuItem_List = new System.Collections.Generic.List<IHamburgerMenuItemViewModel>(); // -------------------- // HOME. // -------------------- Mensaje = "Home"; IHamburgerMenuItem_List.Add(new NavigationItemModel(Mensaje){ NavigationTarget = typeof(Name_MainWindow_Configuracion.MainWindow_Configuracion_Inicio), Glyph = "../images/configuracion/configuracion_home.png" }); IHamburgerMenuItem_List.Add(new SeparatorItem()); // -------------------- // GENERAL. // -------------------- Mensaje = "General"; IHamburgerMenuItem_List.Add(new NavigationItemModel(Mensaje){ NavigationTarget = typeof(Name_MainWindow_Configuracion.MainWindow_Configuracion_General), Glyph = "../images/configuracion/configuracion_general.png" }); IHamburgerMenuItem_List.Add(new SeparatorItem()); // -------------------- // SAVE. // -------------------- Mensaje = "Save"; IHamburgerMenuItem_List.Add(new NavigationItemModel(Mensaje){ NavigationTarget = typeof(Name_MainWindow_Configuracion.MainWindow_Configuracion_Save), IsAlternatePlacementItem = true, Glyph = "../images/configuracion/configuracion_save.png" }); return IHamburgerMenuItem_List; } protected virtual System.Collections.Generic.IList<IHamburgerMenuBottomBarItemViewModel> InitializeBottomBarItems() { return new System.Collections.Generic.List<IHamburgerMenuBottomBarItemViewModel>() { new BottomBarNavigationItemModel() { NavigationTarget = typeof(Name_MainWindow_Configuracion.MainWindow_Configuracion_Guardar), Glyph = "../images/configuracion/configuracion_guardar.png", IsAlternatePlacementItem = true }, new BottomBarCheckableItemModel() { Glyph = "check.png" }, new BottomBarRadioItemModel("RadioGroup"){ Glyph = "Icons/Radio1.png" }, new BottomBarRadioItemModel("RadioGroup"){ Glyph = "Icons/Radio2.png" } }; } void OnSelectedItemChanged() { if (SelectedItem != null) { // IsMenuVisible = HamburgerMenuSelectedItem.Caption != "Simple Page"; } } } }
-------------------------------
Configuracion_save.csCode:<UserControl x:Class="Name_MainWindow_Configuracion.MainWindow_Configuracion_General" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" Background="White" mc:Ignorable="d" d:DesignWidth="650" d:DesignHeight="450"> <UserControl.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="..\Templates\Templates.xaml" /> <ResourceDictionary> </ResourceDictionary> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </UserControl.Resources> <Grid x:Name="Form_Programa" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"> <Grid x:Name="Form_Superior_Grid"> <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="0" > <!-- User Label. --> <Grid x:Name="Form_UsuarioLabel_Grid"> <Label x:Name="User_Label" Style="{StaticResource Destacado}" Content="Usuario" Margin="5,10,0,0" Padding="0" VerticalAlignment="Top"/> <Line X1="5" Y1="30" X2="175" Y2="30" Stroke="#A59E9E" StrokeThickness="2" /> <!-- User Textbox. --> <TextBox x:Name="User_TextBox" Text="XXXXX" Style="{StaticResource TextBox_10}" Width="100" Height="15" Margin="75,10,0,0" Padding="0,2" TextWrapping="Wrap" AcceptsReturn="False" HorizontalAlignment="Left" VerticalAlignment="Top" VerticalContentAlignment="Top"/> </Grid> </StackPanel> </Grid> </Grid> </UserControl>
------------------------
Code:namespace Name_MainWindow_Configuracion { public partial class MainWindow_Configuracion_Guardar : System.Windows.Controls.UserControl { public MainWindow_Configuracion_Guardar() { InitializeComponent(); this.Page_Load(); } protected void Page_Load() { bool Fcn_Correcto = Fcn_AppDatos(); } private bool Fcn_AppDatos() { bool Fcn_Correcto = false; // AT THIS POINT I have to retrieve the values from each subform so that I can save them to a file. // For example, in the form "general_configuration.cs" I have to retrieve the TextBox from the "User_TextBox" field. return Fcn_Correcto; } } }




Reply With Quote
