Browse Source
Merge pull request #3747 from AvaloniaUI/fixes/contextmenu-nre
Fix ContextMenu NullReferenceException
pull/3749/head
Steven Kirk
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
14 additions and
5 deletions
-
src/Avalonia.Controls/ContextMenu.cs
-
tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs
|
|
|
@ -75,7 +75,7 @@ namespace Avalonia.Controls |
|
|
|
{ |
|
|
|
control.PointerReleased -= ControlPointerReleased; |
|
|
|
oldMenu._attachedControl = null; |
|
|
|
((ISetLogicalParent)oldMenu._popup).SetParent(null); |
|
|
|
((ISetLogicalParent)oldMenu._popup)?.SetParent(null); |
|
|
|
} |
|
|
|
|
|
|
|
if (e.NewValue is ContextMenu newMenu) |
|
|
|
|
|
|
|
@ -1,9 +1,5 @@ |
|
|
|
using System; |
|
|
|
using System.Windows.Input; |
|
|
|
using Avalonia.Controls.Primitives; |
|
|
|
using Avalonia.Data; |
|
|
|
using Avalonia.Input; |
|
|
|
using Avalonia.Markup.Data; |
|
|
|
using Avalonia.Platform; |
|
|
|
using Avalonia.UnitTests; |
|
|
|
using Moq; |
|
|
|
@ -159,6 +155,19 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Can_Set_Clear_ContextMenu_Property() |
|
|
|
{ |
|
|
|
using (Application()) |
|
|
|
{ |
|
|
|
var target = new ContextMenu(); |
|
|
|
var control = new Panel(); |
|
|
|
|
|
|
|
control.ContextMenu = target; |
|
|
|
control.ContextMenu = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact(Skip = "The only reason this test was 'passing' before was that the author forgot to call Window.ApplyTemplate()")] |
|
|
|
public void Cancelling_Closing_Leaves_ContextMenuOpen() |
|
|
|
{ |
|
|
|
|