2015-03-27 12 views
11

Tôi đã nhận được dấu vết ngăn xếp dưới đây được báo cáo từ khách hàng. Tôi không biết làm thế nào để tái tạo điều này. Ứng dụng WPF của tôi có số lượng ComboBox hợp lý; Tôi không chắc chắn làm thế nào để xác định ComboBox không thành công cho theo dõi ngăn xếp dưới đây. Đã có người khác nhìn thấy điều này? Bạn có thể giải thích những gì đang diễn ra từ dấu vết ngăn xếp này không? Bất kỳ ý tưởng?sự cố trong ComboBox coerce (không phải mã của tôi)

System.NullReferenceException: Object reference not set to an instance of an object. 
    at System.Windows.Controls.ComboBox.CoerceIsSelectionBoxHighlighted(Object o, Object value) 
    at System.Windows.DependencyObject.ProcessCoerceValue(DependencyProperty dp, PropertyMetadata metadata, EntryIndex& entryIndex, Int32& targetIndex, EffectiveValueEntry& newEntry, EffectiveValueEntry& oldEntry, Object& oldValue, Object baseValue, Object controlValue, CoerceValueCallback coerceValueCallback, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, Boolean skipBaseValueChecks) 
    at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) 
    at System.Windows.DependencyObject.CoerceValue(DependencyProperty dp) 
    at System.Windows.Controls.ComboBox.OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs e) 
    at System.Windows.FocusWithinProperty.FireNotifications(UIElement uie, ContentElement ce, UIElement3D uie3D, Boolean oldValue) 
    at System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState, Action`2 originChangedAction) 
    at System.Windows.ReverseInheritProperty.OnOriginValueChanged(DependencyObject oldOrigin, DependencyObject newOrigin, IList`1 otherOrigins, DeferredElementTreeState& oldTreeState, Action`2 originChangedAction) 
    at System.Windows.Input.KeyboardDevice.ChangeFocus(DependencyObject focus, Int32 timestamp) 
    at System.Windows.Input.KeyboardDevice.PostProcessInput(Object sender, ProcessInputEventArgs e) 
    at System.Windows.Input.InputManager.RaiseProcessInputEventHandlers(ProcessInputEventHandler postProcessInput, ProcessInputEventArgs processInputEventArgs) 
    at System.Windows.Input.InputManager.ProcessStagingArea() 
    at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) 
    at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) 
    at System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawKeyboardActions actions, Int32 scanCode, Boolean isExtendedKey, Boolean isSystemKey, Int32 virtualKey) 
    at System.Windows.Interop.HwndKeyboardInputProvider.PossiblyDeactivate(IntPtr hwndFocus) 
    at System.Windows.Interop.HwndKeyboardInputProvider.FilterMessage(IntPtr hwnd, WindowMessage message, IntPtr wParam, IntPtr lParam, Boolean& handled) 
    at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
    at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
    at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) 
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 
    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) 
+2

Đối với những gì nó có giá trị, tôi đã có cùng một vấn đề ngày hôm nay và được quản lý để giải quyết nó. Tôi đã sử dụng [SetWidthFromItems] (http://stackoverflow.com/a/4414372/1492977) trên combobox của tôi. Nếu tôi xóa danh sách và thêm các mục mới mà không cần gọi SetWidthFromItems, thì tôi sẽ gặp phải lỗi này. Nếu tôi gọi SetWidthFromItems sau khi thêm các phần tử, lỗi không còn xảy ra nữa. –

Trả lời

6

Đây là mã (.NET 4.5.2). Hoặc o không phải là ComboBox hoặc HighlightedElement là không.

Cá nhân, bước đầu tiên của tôi là phân phối PDB để bạn có thể nhận được số dòng trong theo dõi ngăn xếp.

+0

Đây là mã cho cái gì? – MyCodeSucks

+0

@MyCodeSucks Phương pháp ném ngoại lệ. Nhìn vào dấu vết ngăn xếp của mình. – Zer0

+0

Sau đó, anh ta nên là người đăng nó. Nó không thuộc về một câu trả lời. – MyCodeSucks

2

Chúng tôi có một combobox được lọc riêng biệt mà chúng tôi đã thực hiện như một điều khiển người dùng kế thừa từ combobox. Trên các máy tính Windows 10, chúng tôi bắt đầu nhận được lỗi này cho các combobox được lọc trong các biểu mẫu trên các hàng dữ liệu. Chúng ta có một combobox được lọc trong DataGrid.RowDetailsTemplate trên một DataGrid.

Để làm cho lỗi biến mất, chúng tôi đã bỏ qua phụ này trong lớp Filtered_Combobox của chúng tôi.

Protected Overrides Sub OnIsKeyboardFocusWithinChanged(e As DependencyPropertyChangedEventArgs) 
    Try 


    Catch ex As Exception 
    End Try 
End Sub 

Lưu ý: Chúng tôi không đặt bất kỳ mã nào khi ghi đè vì dường như không làm bất cứ điều gì (mặc dù gặp sự cố ứng dụng).

2

Chúng tôi đã gặp sự cố tương tự trên một số phiên bản thời gian chạy và cửa sổ.

Một trong comboboxes của chúng tôi đã theo phong cách

<ComboBox.Style> 
    <Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource {x:Type ComboBox}}"> 
     <Setter Property="IsDropDownOpen" Value="False"/> 
      <Style.Triggers> 
       <Trigger Property="IsKeyboardFocusWithin" Value="True"> 
        <Setter Property="IsDropDownOpen" Value="True" /> 
       </Trigger> 
      </Style.Triggers> 
    </Style> 

Nó bằng cách nào đó, đôi khi sai lầm với lựa chọn làm nổi bật và gây ra ngoại lệ. Có thể điều này hữu ích.

1

gì cuối cùng giải quyết này đối với chúng tôi là để ghi đè lên các sự kiện gây ra vấn đề:

Protected Overrides Sub OnIsKeyboardFocusWithinChanged(e As DependencyPropertyChangedEventArgs) 
    Try 
     'GW 2015-09-20 Added this override to prevent windows 10 crashes on comboboxes within forms within datagrids 

    Catch ex As Exception 
    End Try 
End Sub 
0

Tôi đã nhận lỗi cùng với mã tương tự như những gì maiksaray chia sẻ. Đối với tôi, NullReferenceException tại CoerceIsSelectionBoxHighlighted chỉ xảy ra trên Windows 10, không phải trên máy tính Windows 7 dev của tôi. Nó chỉ xảy ra lần đầu tiên hộp combo được bấm để mở.

Trong trường hợp của tôi, tôi đã lập trình mở và đóng các combobox khi xem nạp:

public MyView() 
{ 
    InitializeComponent(); 
    Loaded += OnLoaded; 
} 

private void comboBox1_DropDownOpened(object sender, EventArgs e) 
{ 
    comboBox1.ItemsSource = MyClass.GetComboBoxList(); 
} 

private void OnLoaded(object sender, RoutedEventArgs e) 
{ 
    comboBox1.IsDropDownOpen = true; 
    comboBox1.IsDropDownOpen = false; 
} 

Tôi đã làm điều này như là cách giải quyết cho vấn đề khác, được mô tả ở đây: http://blog.elgaard.com/2009/09/03/wpf-making-combo-box-items-disabled-also-when-accessed-using-the-keyboard/

Các lỗi đã xảy ra sau khi DevicesComboBox_DropDownOpened hoàn tất. Tuy nhiên, nó chỉ xảy ra với mã số Đã tải trước. Nếu tôi đã nhận xét Đã tải + = OnLoaded, thì tôi đã không gặp lỗi.

Giải pháp cho tôi đơn giản là tránh mở và đóng chương trình ComboBox theo chương trình.

Các vấn đề liên quan