【问题标题】:Wpf ComboBox throws exception on combobox in windows 7Wpf ComboBox在Windows 7中的组合框上引发异常
【发布时间】:2015-05-18 17:39:45
【问题描述】:

我在 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 安装向导不适用,或被您计算机上的其他情况阻止。详情请点击以下链接。

【问题讨论】:

  • 你能展示你用来定义组合框的 XAML 代码吗?
  • 你最近清理和重建了吗?您是否在没有调试器的情况下在 Windows 8 机器上尝试过?
  • @O.R.Mapper 代码现已添加
  • @FelixCastor 是的,我已经完成了,而且它在我尝试过的每台 Windows 8 机器上都能正常工作,但在 Windows 7 上崩溃
  • 你的转换器是如何定义的?

标签: c# .net wpf combobox


【解决方案1】:

我把它放在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;
    }
}

【讨论】:

  • 它不会出现在那个异常上
猜你喜欢
  • 2011-04-01
  • 2013-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-02
相关资源
最近更新 更多