Does anyone know how to change the Properties.Settings.Default.{} form App.xaml.cs?
Frage
Can anyone point me in the right direction? I need some way to change Properties.Settings.Default when my application starts by adding values from am xml if it exists and bypass the StartupUri from App.xaml, actually creating a different window. If that xml file doesn't exist Run the StartupUri from the App.xaml (which will be a login Window).
Any ideas?
Thanks before hand.
Lösung
remove the startupuri from your app.xaml an override OnStartup() in your app.xaml.cs
protected override void OnStartup(StartupEventArgs e)
{
//todo settings
var login = new LoginWindow();
var result = login.ShowDialog()
//do something with result
this.MainWindow = new MyMainWindow();
this.MainWindow.Show();
}
i dont know what you really want with your Properties.Settings...
Andere Tipps
In case anyone is still looking.. Lookup the property values in Properties.Settings.Default from the OnStartup method in app.xaml.cs, use the property to determine if the user wants a login:
App.xaml.cs:
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
bool b = YourNamespace.Properties.Settings.Default.SettingUseLogin;
if (b)
this.StartupUri = new System.Uri("LoginWindow.xaml", System.UriKind.Relative);
else
this.StartupUri = new System.Uri("MainWindow.xaml", System.UriKind.Relative);
}
}