C# WPF 应用程序在 Visual 中启动,但在 运行 时直接启动
C# WPF application launches in Visual, but not when ran directly
我正在制作一个 WPF 应用程序,它按预期工作,但只有当我 运行 它在 Visual Studio 中时才有效。
如果我导航到该文件夹并从那里 运行 它,它就会崩溃而没有任何消息。
这里有一个视频演示:http://youtu.be/gVONAT387VQ
此应用程序在 0.9 之前运行良好。从那时起,我只添加了一个新的网格,开始使用 Properties.Settings.Default 并添加了一个只读文件的处理程序(因为这个应用程序读取然后写入一个配置文件)。 none 其中似乎会导致此问题。
编辑:
找到原因。事件查看器写出错误。
我刚刚实现的处理异常的部分消息框:
System.Windows.Markup.XamlParseException: The invocation of the constructor on type 'DayZ_Config_Tweak_tool.MainWindow' that matches the specified binding constraint threw an exception. ---> System.FormatException: Token is not valid.
at MS.Internal.Parsers.ParseBrush(String brush, IFormatPRovider formatProvider, ITypeDescriptorContext contex)
at System.Windows.Media.Brush.Parse(String value, ITypeDescriptorContext context)
at System.Windows.Media.BrushConverter:ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at DayZ_Config_Tweak_Tool.MainWindow.InitializeButtons() in #Path to xaml.cs#:line 222
at DayZ_Config_Tweak_tool.MainWindow..ctor() in #Path to xaml.cs#:line 44
我的设置是十六进制颜色字符串,他们错过了主题标签“000000”而不是“#000000”。
在调试 运行 期间,我的应用程序自动加载了 "Dark" 主题,该主题在应用程序启动后立即初始化,但是一旦应用程序 运行 由于某种原因处于开发环境之外,这种情况就不会发生.
添加主题标签解决了问题。
基本上 运行 Devenv 之外的应用程序意味着您的 Properties.Settings.Default 将是空的!!在 InitializeComponent() 之前检查并加载它;解决了所有问题!
我正在制作一个 WPF 应用程序,它按预期工作,但只有当我 运行 它在 Visual Studio 中时才有效。
如果我导航到该文件夹并从那里 运行 它,它就会崩溃而没有任何消息。
这里有一个视频演示:http://youtu.be/gVONAT387VQ
此应用程序在 0.9 之前运行良好。从那时起,我只添加了一个新的网格,开始使用 Properties.Settings.Default 并添加了一个只读文件的处理程序(因为这个应用程序读取然后写入一个配置文件)。 none 其中似乎会导致此问题。
编辑:
找到原因。事件查看器写出错误。
我刚刚实现的处理异常的部分消息框:
System.Windows.Markup.XamlParseException: The invocation of the constructor on type 'DayZ_Config_Tweak_tool.MainWindow' that matches the specified binding constraint threw an exception. ---> System.FormatException: Token is not valid.
at MS.Internal.Parsers.ParseBrush(String brush, IFormatPRovider formatProvider, ITypeDescriptorContext contex)
at System.Windows.Media.Brush.Parse(String value, ITypeDescriptorContext context)
at System.Windows.Media.BrushConverter:ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at DayZ_Config_Tweak_Tool.MainWindow.InitializeButtons() in #Path to xaml.cs#:line 222
at DayZ_Config_Tweak_tool.MainWindow..ctor() in #Path to xaml.cs#:line 44
我的设置是十六进制颜色字符串,他们错过了主题标签“000000”而不是“#000000”。 在调试 运行 期间,我的应用程序自动加载了 "Dark" 主题,该主题在应用程序启动后立即初始化,但是一旦应用程序 运行 由于某种原因处于开发环境之外,这种情况就不会发生. 添加主题标签解决了问题。
基本上 运行 Devenv 之外的应用程序意味着您的 Properties.Settings.Default 将是空的!!在 InitializeComponent() 之前检查并加载它;解决了所有问题!