CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2020
    Posts
    6

    How can I retrieve the configuration values in a MainViewModel system

    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
    ---------------------
    Code:
    <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>
    MainViewModel.cs
    ---------------------
    Code:
    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_General.xaml
    -------------------------------
    Code:
    <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>
    Configuracion_save.cs
    ------------------------
    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;
            }
        }
    }
    Last edited by 2kaud; August 26th, 2020 at 02:26 AM. Reason: Added code tags

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How can I retrieve the configuration values in a MainViewModel system

    In WPF, the xaml is bound to a data model. You would retrieve values from the model (not from the xaml). Search google for "wpf mvvm examples".

  3. #3
    Join Date
    Aug 2020
    Posts
    6

    Re: How can I retrieve the configuration values in a MainViewModel system

    This case is different because the .cs are entered inside the Hambuguermenu control.

    I open the form by:
    // Configuracion Form. Open().
    dynamic FrmFormulario = new Name_MainWindow_Configuracion.MainWindow_Configuracion();
    FrmFormulario.ShowDialog();

    And I can ask for FrmForm, but I don't know how to ask for something like: FrmForm.Form_HamburgerMenu.ItemsSource [1] .User_TextBox.Text

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How can I retrieve the configuration values in a MainViewModel system

    Post the question to the DevExpress forum.

  5. #5
    Join Date
    Aug 2020
    Posts
    6

    Re: How can I retrieve the configuration values in a MainViewModel system

    Is not possible to post in DevExpress because License is required.

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How can I retrieve the configuration values in a MainViewModel system

    Quote Originally Posted by zequion View Post
    Is not possible to post in DevExpress because License is required.
    How are you developing without a license?

  7. #7
    Join Date
    Aug 2020
    Posts
    6

    Re: How can I retrieve the configuration values in a MainViewModel system

    The license costs $ 2,199 per year. I don't have a job and I entertain myself doing programs. cleared up !!

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How can I retrieve the configuration values in a MainViewModel system

    Quote Originally Posted by zequion View Post
    The license costs $ 2,199 per year. I don't have a job and I entertain myself doing programs. cleared up !!
    Hope you find a job. Good luck.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured