c # Wpf приложение вылетает на W10 - PullRequest
0 голосов
/ 19 сентября 2019

Я боролся с этой проблемой, в течение 2 дней я сделал приложение WPF с W7.приложение отлично работает с W7, но когда я хочу запустить его с W10.Это работает с самого начала, но когда я хочу открыть окно, оно вылетает, я пытался отладить некоторый MessageBox в моем коде позади, но когда он вызывает mutliValueconverter и вылетает, я зашел в журнал событий и получил ошибку с KernelBase.dll.Вот мой класс MultiValueConverter и скриншот ошибки в журнале событий [! Text] [журнал событий 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 RunTime

eventlog2 eventlog3

РЕДАКТИРОВАТЬ: Мой экран трассировки стека был неполным, вот трассировка полного стека в XMLformat Может кто-нибудь еще раз сказать, что это не работает для меня

Приложение: EasyMaintenance.exe Версия du Framework:
v4.0.30319 Описание: процесс может быть исключительным, если не исключение.Сведения об исключении: 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.OnStyleCang (Windows.DependencyObject, System.Windows.DependencyPropertyChangedEventArgs) à System.Windows.PropertyChangedCallback.Invoke (System.Windows.DependencyObject, System.Windows.DependencyPropertyChangedEventArgs) à System.Windows.DependedOg.Wevent.WeventProWeper.Wevent.Wevent.Wevent.Wevent.Wevent.Wevent.Wevent.Wevent.Wevent.Wevent.Wevent.Wevent.Wevent.Wevent.Wevent.Wevent.Wevent.Wevent.Wevent.Wevent.Wer.Oper.Wer.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.We.DependencyObject.CoerceValue (System.Windows.DependencyProperty) à System.Windows.Controls.DataGridHelper.TransferProperty (System.Windows.DependencyObject, System.Windows.DependencyProperty) à System.Windows.Control.DataGridCumnCW.Ont.DataGridColumn, System.Windows.Controls.DataGridColumn) à System.Windows.Controls.DataGridCell.OnColumnChanged (System.Object, System.Windows.DependencyPropertyChangedEventArgs) à System.Windows.DependencyObdency.gsedEd.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, Boole., Boole. System. Boole.Windows.OperationType) à System.Windows.DependencyObject.SetValueCommon (System.Windows.DependencyProperty, System.Object, System.Windows.PropertyMetadata, логическое значение, логическое значение, System.Windows.OperationType, логическое значение) à System.WindowsjectSepenOSystem.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.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer (System.Windows.DependencyObject) à System.Windows.Controls.DataGridCellsPanel.InsertContainer (Int32, System.Windows.UieleClement)DataGridCellsPanel.AddContainerFromGenerator (Int32, System.Windows.UIElement, Boolean) à System.Windows.Controls.DataGridCellsPanel.GenerateChild (System.Windows.Controls.Primitives.IItemContainerGenerator, System.Wrols.Gat32.Gindows.izeByRef, 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) à MS.Internal.Helper.MeasureElementWithSingleChild (.Windows.UIElement, System.Windows.Size) ® System.Windows.Controls.ItemsPresenter.MeasureOverride (System.Windows.Size) ® System.Windows.FrameworkElement.MeasureCore (System.Windows.Size) ® System.Windows.UIElement.Мера (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.Windows.Controls.Primitives.IContainItemStorage ByRef, System.Windows.Controls.Primitives.IContainItemStorage ByRef, System.Object ByRef, логический ByRef, двойной ByRef, двойной ByRef, логический ByRef, логический ByRef, System.Colject.ByRef, System.Collections.IList ByRef, Int32 ByRef, логический ByRef, логический 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.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, логический ByRef, логический, логический, Boolean, Boolean, Boolean, Boolean ByRef, Boolean ByRef) à System.Windows.Controls.VirtualizingStackPanel.MeasureOverrideImpl (System.Windows.Size, System.Nullable 1<Double> ByRef, System.Collections.Generic.List 1 ByRef, System.Nullable`1 ByRef, Boolele).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.Object) à System.Windows.Media.MediaContext.Resize (System.Windows.Media.ICompositionTarget) à System.Windows.Interop.HwndTarget.OnResize () à System.Windows.Interop.HwndTarget.HandleMessage (MS.Interop.WindowMessage, IntPtr, IntPtr) ® System.Windows.Interop.HwndSource.HwndTargetFilterMessage (IntPtr, Int32, IntPtr, IntPtr, логическое значение ByRef) - MS.Win32.HwndWrapper.MS.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) MS.Win32.HwndSubclass.SubclassWndProc (IntPtr) Int32, Int32, Int32, Int321021 *

и вот 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>

1 Ответ

0 голосов
/ 19 сентября 2019

Что должен делать этот триггер?

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

Кажется, что вы пытаетесь установить фон DataGridCell на Chocolate всякий раз, когда фон Chocolate?

В результате вы получите бесконечную рекурсию, так как всякий раз, когда вы меняете фон на Chocolate, триггер срабатывает и меняет фон на Chocolate, вызывая триггер, который меняет фон на Chocolate и т. Д..

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...