Browse Source
Merge pull request #5200 from donandren/issues/contextmenuopen
Fix ContextMenu Open
pull/5283/head
Max Katz
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
50 additions and
1 deletions
-
src/Avalonia.Controls/ContextMenu.cs
-
tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs
|
|
|
@ -246,7 +246,7 @@ namespace Avalonia.Controls |
|
|
|
/// <summary>
|
|
|
|
/// Opens the menu.
|
|
|
|
/// </summary>
|
|
|
|
public override void Open() => throw new NotSupportedException(); |
|
|
|
public override void Open() => Open(null); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Opens a context menu on the specified control.
|
|
|
|
|
|
|
|
@ -44,6 +44,55 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Open_Should_Use_Default_Control() |
|
|
|
{ |
|
|
|
using (Application()) |
|
|
|
{ |
|
|
|
var sut = new ContextMenu(); |
|
|
|
var target = new Panel |
|
|
|
{ |
|
|
|
ContextMenu = sut |
|
|
|
}; |
|
|
|
|
|
|
|
var window = new Window { Content = target }; |
|
|
|
window.ApplyTemplate(); |
|
|
|
window.Presenter.ApplyTemplate(); |
|
|
|
|
|
|
|
bool opened = false; |
|
|
|
|
|
|
|
sut.MenuOpened += (sender, args) => |
|
|
|
{ |
|
|
|
opened = true; |
|
|
|
}; |
|
|
|
|
|
|
|
sut.Open(); |
|
|
|
|
|
|
|
Assert.True(opened); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Open_Should_Raise_Exception_If_AlreadyDetached() |
|
|
|
{ |
|
|
|
using (Application()) |
|
|
|
{ |
|
|
|
var sut = new ContextMenu(); |
|
|
|
var target = new Panel |
|
|
|
{ |
|
|
|
ContextMenu = sut |
|
|
|
}; |
|
|
|
|
|
|
|
var window = new Window { Content = target }; |
|
|
|
window.ApplyTemplate(); |
|
|
|
window.Presenter.ApplyTemplate(); |
|
|
|
|
|
|
|
target.ContextMenu = null; |
|
|
|
|
|
|
|
Assert.ThrowsAny<Exception>(()=> sut.Open()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Closing_Raises_Single_Closed_Event() |
|
|
|
{ |
|
|
|
|