有谁知道如何更改Properties.Settings.Default。{}表单App.xaml.cs?

时间:2011-11-17 10:41:41

标签: wpf xml app.xaml

有人能指出我正确的方向吗?我需要一些方法来改变Properties.Settings.Default当我的应用程序启动时添加am xml中的值(如果它存在)并从App.xaml绕过StartupUri,实际创建一个不同的窗口。如果该xml文件不存在从App.xaml运行StartupUri(这将是一个登录窗口)。

有什么想法吗?

先谢谢。

2 个答案:

答案 0 :(得分:2)

如果有人仍然在寻找..从app.xaml.cs中的OnStartup方法查找Properties.Settings.Default中的属性值,使用该属性来确定用户是否想要登录:

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);

    }
}

答案 1 :(得分:1)

从app.xaml中删除startupuri,在app.xaml.cs中覆盖OnStartup()

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();
}

我不知道你真正想要的东西.Settings ......