c# - 如何防止加载 WPF 应用程序?

标签 c# .net wpf startup

我希望 WPF 应用程序仅在特定条件下启动。我尝试了以下但没有成功:

public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        if (ConditionIsMet) // pseudo-code
        {
            base.OnStartup(e);
        }
    }
}

但即使不满足条件,应用程序也能正常运行

最佳答案

试试这个:

protected override void OnStartup(StartupEventArgs e)
{
    base.OnStartup(e);
    if (MyCondition)
    {
        ShowSomeDialog("Hey, I Can't start because...");
        this.Shutdown();
    }
}

关于c# - 如何防止加载 WPF 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3719562/

相关文章:

wpf - 如何在 wpf 中使用 MVVM 处理 ComboBox 的 SelectionChanged 事件?

c# - FormView.FindControl() : object reference error

.net - 点网4.0.30319初始化错误

.net - 从 ListViewItem 中删除高亮效果

c# - 是否可以在没有 Windows 机器的情况下开发 Windows Phone 7 应用程序?

c# - 将列表存储在所有用户都可以访问的内存中

c# - 样式化 Xamarin.Forms DisplayAlert

c# - Identity 2.0 : Creating custom ClaimsIdentity eg: User. Identity.GetUserById<int>(int id) 用于每个请求验证

.net - .NET 的 JavaCC?

c# - 反序列化期间 XML 文档 (0, 0) 中存在错误