【问题标题】:Does anyone know how to change the Properties.Settings.Default.{} form App.xaml.cs?有谁知道如何更改 App.xaml.cs 的 Properties.Settings.Default.{} 表单?
【发布时间】:2011-11-17 10:41:40
【问题描述】:

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

有什么想法吗?

先谢谢了。

【问题讨论】:

    标签: wpf xml app.xaml


    【解决方案1】:

    如果有人还在寻找.. 从 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);
    
        }
    }
    

    【讨论】:

      【解决方案2】:

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

      我不知道您真正想要的 Properties.Settings...

      【讨论】:

      • 我需要为我的应用程序实现某种记住密码的功能,并且我使用 Properties.Settings 作为某种 $_SESSION 变量。谢谢
      • 谁能建议如何更有效地做到这一点?谢谢
      猜你喜欢
      • 2017-11-04
      • 2016-06-12
      • 1970-01-01
      • 2017-06-04
      • 2011-06-01
      • 2011-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多