c# Wpf 应用程序在 W10 上崩溃



我一直在为这个问题苦苦挣扎,2 天了 我用 W7 做了一个 WPF 应用程序。该应用程序在 W7 上运行良好,但是当我想使用 W10 运行它时。 它在开始时有效,但是当我想打开一个窗口时,它会崩溃 我尝试在我的代码隐藏中使用一些 MessageBox 进行调试,但是当它调用 mutliValueconverter 并崩溃时 我去查看事件日志,但内核数据库出错.dll 这是我的多值转换器类 以及事件日志中错误的屏幕截图 [!文本][事件日志 1]1

using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
namespace EasyMaintenance
{
public class HighlighterConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, 
CultureInfo culture)
{           
if (values[1] is DataRow)
{
var cell = (DataGridCell)values[0];
var row = (DataRow)values[1];
var columnName = cell.Column.SortMemberPath;
//MessageBox.Show(cell.ToString());
//
foreach (arcad arcad in Fichess.arcad_list)
{
try
{
if (arcad.couleur == "rouge" && row[columnName].ToString() == arcad.lib && arcad.couleur2 == "vert")
{
// MessageBox.Show("Coloration en Rouge");
return Brushes.Red;
}
if (arcad.couleur2 == "vert" && row[columnName].ToString() == arcad.lib)
{
// MessageBox.Show("Coloration en Vert");
return Brushes.Green;
}
if (arcad.couleur2 == "Blue" && row[columnName].ToString() == arcad.lib)
{
// MessageBox.Show("Coloration en bleu");
return Brushes.Blue;
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
if (arcad.couleur2 == "blanche" && row[columnName].ToString() == arcad.lib)
{
// MessageBox.Show("Coloration en chocolat");
return Brushes.Chocolate;
}
}
}
return SystemColors.AppWorkspaceColor;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

}

这是 .NET 运行时的事件日志错误

事件日志2 事件日志3

编辑: 我的堆栈跟踪屏幕不完整,这里是XML格式的完整堆栈跟踪 有人可以重新编辑它对我不起作用吗

应用程序 : EasyMaintenance.exe Version du Framework :
v4.0.30319 Description : le processus a été arrêté en存在的理由是非Gérée例外。 Informations sur l'exception : System.InvalidOperationException à System.Windows.TriggerBase.Seal() à System.Windows.Trigger.Seal() à System.Windows.TriggerCollection.Seal() à System.Windows.Style.Seal() à System.Windows.StyleHelper.UpdateStyleCache(System.Windows.FrameworkElement, System.Windows.FrameworkContentElement, System.Windows.Style, System.Windows.Style, System.Windows.Style ByRef) à System.Windows.FrameworkElement.OnStyleChanged(System.Windows.DependencyObject, System.Windows.DependencyPropertyChangedEventArgs) à System.Windows.PropertyChangedCallback.Invoke(System.Windows.DependencyObject, System.Windows.DependencyPropertyChangedEventArgs) à System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs) à System.Windows.FrameworkElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs) àSystem.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs) à System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex, System.Windows.DependencyProperty, System.Windows.PropertyMetadata, System.Windows.EffectiveValueEntry, System.Windows.EffectiveValueEntry ByRef, Boolean, Boolean, System.Windows.OperationType) à System.Windows.DependencyObject.CoerceValue(System.Windows.DependencyProperty) à System.Windows.Controls.DataGridHelper.TransferProperty(System.Windows.DependencyObject, System.Windows.DependencyProperty) à System.Windows.Controls.DataGridCell.OnColumnChanged(System.Windows.Controls.DataGridColumn, System.Windows.Controls.DataGridColumn) à System.Windows.Controls.DataGridCell.OnColumnChanged(System.Object, System.Windows.DependencyPropertyChangedEventArgs) à System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs) àSystem.Windows.FrameworkElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs) à System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs) à System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex, System.Windows.DependencyProperty, System.Windows.PropertyMetadata, System.Windows.EffectiveValueEntry, System.Windows.EffectiveValueEntry ByRef, Boolean, Boolean, System.Windows.OperationType) à System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty, System.Object, System.Windows.PropertyMetadata, Boolean, Boolean, System.Windows.OperationType, Boolean) à System.Windows.DependencyObject.SetValue(System.Windows.DependencyPropertyKey, System.Object) à System.Windows.Controls.DataGridCell.PrepareCell(System.Object, System.Windows.Controls.DataGridRow, Int32) àSystem.Windows.Controls.Primitives.DataGridCellsPresenter.PrepareContainerForItemOverride(System.Windows.DependencyObject, System.Object) à System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(System.Windows.DependencyObject, System.Object) à System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(System.Windows.DependencyObject) à System.Windows.Controls.DataGridCellsPanel.InsertContainer(Int32, System.Windows.UIElement, Boolean) à System.Windows.Controls.DataGridCellsPanel.AddContainerFromGenerator(Int32, System.Windows.UIElement, Boolean) à System.Windows.Controls.DataGridCellsPanel.GenerateChild(System.Windows.Controls.Primitives.IItemContainerGenerator, System.Windows.Size, System.Windows.Controls.DataGridColumn, Int32 ByRef, System.Windows.Size ByRef) à System.Windows.Controls.DataGridCellsPanel.DetermineRealizedColumnsBlockList(System.Windows.Size) àSystem.Windows.Controls.DataGridCellsPanel.MeasureOverride(System.Windows.Size) à System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) à System.Windows.UIElement.Measure(System.Windows.Size) à 女士。Internal.Helper.MeasureElementWithSingleChild(System.Windows.UIElement, System.Windows.Size) à System.Windows.Controls.ItemsPresenter.MeasureOverride(System.Windows.Size) à System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) à System.Windows.UIElement.Measure(System.Windows.Size) à System.Windows.Controls.Control.MeasureOverride(System.Windows.Size) à System.Windows.Controls.Primitives.DataGridCellsPresenter.MeasureOverride(System.Windows.Size) à System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) à System.Windows.UIElement.Measure(System.Windows.Size) à System.Windows.Controls.Grid.MeasureCell(Int32, Boolean) à System.Windows.Controls.Grid.MeasureCellsGroup(Int32, System.Windows.Size, Boolean, Boolean, Boolean ByRef) àSystem.Windows.Controls.Grid.MeasureOverride(System.Windows.Size) à System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) à System.Windows.UIElement.Measure(System.Windows.Size) à System.Windows.Controls.Border.MeasureOverride(System.Windows.Size) à System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) à System.Windows.UIElement.Measure(System.Windows.Size) à System.Windows.Controls.Control.MeasureOverride(System.Windows.Size) à System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) à System.Windows.UIElement.Measure(System.Windows.Size) à System.Windows.Controls.VirtualizingStackPanel.MeasureChild(System.Windows.Controls.Primitives.IItemContainerGenerator ByRef, System.Windows.Controls.Primitives.IContainItemStorage ByRef, System.Windows.Controls.Primitives.IContainItemStorage ByRef, System.Object ByRef, Boolean ByRef, Double ByRef, Double ByRef, Boolean ByRef, Boolean ByRef, System.Collections.IList ByRef,System.Object ByRef, System.Collections.IList ByRef, Int32 ByRef, Boolean ByRef, Boolean ByRef, System.Windows.Size ByRef, System.Windows.Rect ByRef, System.Windows.Controls.VirtualizationCacheLength ByRef, System.Windows.Controls.VirtualizationCacheLengthUnit ByRef, Boolean ByRef, Double ByRef, System.Windows.Size ByRef, System.Windows.Size ByRef, System.Windows.Size ByRef, System.Windows.Size ByRef, System.Windows.Size ByRef, System.Windows.Size ByRef, System.Windows.Size ByRef, System.Windows.Size ByRef, Boolean ByRef, 布尔值, 布尔值, 布尔值, 布尔值, 布尔值, 布尔值 ByRef, 布尔值 ByRef) à System.Windows.Controls.VirtualizingStackPanel.MeasureOverrideImpl(System.Windows.Size, System.Nullable1<Double> ByRef, System.Collections.Generic.List1 ByRef, System.Nullable'1 ByRef, Boolean) à System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(System.Windows.Size) à System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(System.Windows.Size)à System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) à System.Windows.UIElement.Measure(System.Windows.Size) à System.Windows.ContextLayoutManager.UpdateLayout() à System.Windows.ContextLayoutManager.UpdateLayoutCallback(System.Object) à System.Windows.Media.MediaContext+InvokeOnRenderCallback.DoWork() à System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() à System.Windows.Media.MediaContext.RenderMessageHandlerCore(System.Object) à System.Windows.Media.MediaContext.RenderMessageHandler(System.Object) à System.Windows.Media.MediaContext.Resize(System.Windows.Media.ICompositionTarget) à System.Windows.Interop.HwndTarget.OnResize() à System.Windows.Interop.HwndTarget.HandleMessage(MS.Internal.Interop.WindowMessage, IntPtr, IntPtr) à System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) à 女士。Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) à女士。Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) à System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) à System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) à System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32) à 女士。Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, 国际)

这是它在尝试读取时崩溃的 Xaml

<DataGrid x:Name="arcad_Grid"  HorizontalAlignment="Left" Height="499" Margin="12,31,0,0" VerticalAlignment="Top" Width="190" Loaded="getArcadVersion" AutoGenerateColumns="true"  SelectionMode="Single" CanUserAddRows="False" CanUserResizeColumns="False" CanUserResizeRows="False" SelectionUnit="FullRow"  SelectionChanged="Arcad_Grid_SelectionChanged" VirtualizingStackPanel.VirtualizationMode="Standard"
VirtualizingStackPanel.CleanUpVirtualizedItem="dataGrid1_CleanUpVirtualizedItem" Grid.Column="1" Grid.Row="2" Grid.RowSpan="3">
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Background">
<Setter.Value>
<MultiBinding Converter="{StaticResource          myHighlighterConverter}" >
<MultiBinding.Bindings>
<Binding RelativeSource="{RelativeSource Self}"></Binding>
<Binding Path="Row"></Binding>
</MultiBinding.Bindings>
</MultiBinding>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="DataGridCell.IsSelected" Value="True">
<Setter Property="Background"  Value="Chocolate" />
</Trigger>
<Trigger Property="DataGridCell.Background" Value="Chocolate" >
<Setter Property="Background"  Value="Chocolate" />
</Trigger>

</Style.Triggers>
</Style>
</DataGrid.CellStyle>
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Chocolate"/>
</DataGrid.Resources>

这个触发器应该做什么?

<Trigger Property="DataGridCell.Background" Value="Chocolate" >
<Setter Property="Background"  Value="Chocolate" />
</Trigger>

似乎您正在尝试将DataGridCell的背景设置为Chocolate每当其背景Chocolate时?

你最终会得到无限递归,因为每当你将背景更改为Chocolate时,触发器就会触发并将背景更改为Chocolate,触发触发器,将背景更改为Chocolate,等等。

最新更新