Wpf ComboBox在Windows 7中的组合框上抛出异常

时间:2015-05-18 17:39:46

标签: c# .net wpf combobox

我在Windows 8上制作了一个WPF应用程序(Framework 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安装向导不适用,或被计算机上的其他情况阻止。请点击以下链接了解更多详情。

1 个答案:

答案 0 :(得分:0)

我把它放在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;
    }
}
相关问题