簡體   English   中英

C#WPF應用程序在Visual中啟動,但在直接運行時無法啟動

[英]C# WPF application launches in Visual, but not when ran directly

我正在制作WPF復本,它可以按預期工作,但僅當我在Visual Studio中運行它時才可以。

如果我導航到該文件夾​​並從那里運行它,它只會崩潰而沒有任何消息。

這是一個視頻演示:http: //youtu.be/gVONAT387VQ

在0.9之前,該應用程序運行良好。 從那時起,我只添加了一個新的Grid,開始使用Properties.Settings.Default並添加了ReadOnly文件的處理程序(因為此應用程序先讀取然后寫入配置文件)。 這些似乎都不會導致此問題。

編輯:

發現原因。 事件查看器將錯誤寫出。

我剛剛實現的帶有已處理異常的消息框的一部分:

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”。 在調試運行期間,我的應用程序自動加載了在應用程序啟動后立即初始化的“黑暗”主題,但是一旦出於某種原因應用程序在開發環境之外運行,就不會發生這種情況。 添加主題標簽可解決此問題。

基本上在Devenv外部運行應用程序意味着您的Properties.Settings.Default將為空! 檢查並在InitializeComponent()之前加載它; 解決了所有問題!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM