簡體   English   中英

WPF ComboBox在Windows 7中的組合框上引發異常

[英]Wpf ComboBox throws exception on combobox in windows 7

我在Windows 8上制作了WPF應用程序(框架4.5),該應用程序使用常規的組合框和一些其他控件。 我面臨的問題是它在Windows 7上崩潰:

A first chance exception of type System.Windows.Markup.XamlParseException occurred in PresentationFramework.dll
Additional information: 'Initialization of 'System.Windows.Controls.ComboBox' threw an exception.'

這是我的組合框XAML:

 <ComboBox Name="bloodGroupList" Grid.Row="7" Grid.Column="1"
         SelectedIndex="{Binding Patient.BloodGroup, Converter={StaticResource StrToBlood}, Mode=TwoWay}"
         IsEnabled="{Binding IsEditing}"
         VerticalAlignment="Center" Margin="5,5.5" VerticalContentAlignment="Center"
         BorderThickness="0" Height="22" TabIndex="4" HorizontalContentAlignment="Stretch">
    <ComboBoxItem Content="A+" />
    <ComboBoxItem Content="A-" />
    <ComboBoxItem Content="B+" />
    <ComboBoxItem Content="B-" />
    <ComboBoxItem Content="O+" />
    <ComboBoxItem Content="O-" />
    <ComboBoxItem Content="AB+" />
    <ComboBoxItem Content="AB-" />
</ComboBox>

我在某個博客上閱讀了有關運行此修復程序NDP45-KB2750147-x64但它說:

軟件更新KB2750147安裝向導不適用,或者被計算機上的其他狀況所阻止。 請單擊下面的鏈接以獲取更多詳細信息。

我將其放在App.xaml.cs文件中以獲取完整的堆棧跟蹤。 這可能是解決問題的有用方法。

using System;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Threading;

public partial class App : Application
{
    void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
    {
        // All unhandled exceptions come here. A stacktrace is saved as a text file with date and time.

        StackTrace st = new StackTrace(e.Exception);
        string fileName = DateTime.Now.ToString().Replace('/', '-').Replace(':', '-') + " errors.txt";
        fileName = @"C:\Users\Public\" + fileName;
        System.Windows.MessageBox.Show("Critical Error. Closing program.\nStacktrace can be found:" + fileName);
        using (var stream = new FileStream(fileName, FileMode.OpenOrCreate))
        {
            using (var strWrite = new StreamWriter(stream))
            {
                strWrite.Write(st.ToString());
            }
        }

        if (MainWindow != null)
        {
            MainWindow.Close();
        }
        else
        {
            Environment.Exit(0);
        }

        e.Handled = true;
    }
}

暫無
暫無

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

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