繁体   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