how to show windows previous to MainWindow the first time the application is opened in WPF c #

0

I am developing a program in WPF c # where I need to show terms and conditions as well as register user data the first time this opens the app after installing

MainWindow is the main window but I have not found a way to determine if it is the first time the user opens the program, and how to open other windows before the main window

I hope someone can help me!

    
asked by Antonio Hernandez 14.04.2017 в 08:44
source

2 answers

1

An option could manage a variable in the AppConfig of the program, in which you verify if it is the first time that you enter the system or not, according to that variable.

AppConfig

<configuration>
   <appSettings>
     <add key ="firstTime" value = "1"/>
   </appSettings>
</configuration>

Now in your code, you would do the query at key and check it and depending on that, do what you want.

string value = System.Configuration.ConfigurationManager.AppSettings[firstTime];
if (value = "1")
{
   //haces lo que ocupes


   //ahora guardas el valor nuevo diferente de 1
   string appPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
   string configFile = System.IO.Path.Combine(appPath, "App.config");
   ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
   configFileMap.ExeConfigFilename = configFile;
   System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
   config.AppSettings.Settings["firstTime"].Value = "0";
   config.Save();
}
    
answered by 20.04.2017 в 17:45
1

Randall Sandoval's answer can be used. But there are also other ways to do it and I think that contributing would not go wrong.

You could create a file with a specific name and verify if it exists, but it exists then it is because it is the first time it starts and when you do the startup configuration, you create the file.

public bool VerificarSiPrimerInicio()
{
   var filePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "init.app");

  return System.IO.FileExists(filePath); // si true es porque ya fue configurada
}

And this method you would only call it when it was already configured

public void AplicacionConfigurada()
 {
                   var filePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "init.app");

                  System.IO.File.Create(filePath).Close(); 

 }
    
answered by 25.04.2017 в 14:09