Browse Source
Merge pull request #3060 from AvaloniaUI/fixes/menu-initially-selected
Fix first menu item showing as selected when shown
pull/3065/head
Benedikt Stebner
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
40 additions and
1 deletions
-
src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
-
tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs
|
|
|
@ -1088,7 +1088,9 @@ namespace Avalonia.Controls.Primitives |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
SelectedIndex = _updateSelectedIndex != int.MinValue ? _updateSelectedIndex : 0; |
|
|
|
SelectedIndex = _updateSelectedIndex != int.MinValue ? |
|
|
|
_updateSelectedIndex : |
|
|
|
AlwaysSelected ? 0 : -1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -109,6 +109,43 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
Assert.True(items[1].IsSelected); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void SelectedIndex_Should_Be_Minus_1_After_Initialize() |
|
|
|
{ |
|
|
|
var items = new[] |
|
|
|
{ |
|
|
|
new Item(), |
|
|
|
new Item(), |
|
|
|
}; |
|
|
|
|
|
|
|
var target = new ListBox(); |
|
|
|
target.BeginInit(); |
|
|
|
target.Items = items; |
|
|
|
target.Template = Template(); |
|
|
|
target.EndInit(); |
|
|
|
|
|
|
|
Assert.Equal(-1, target.SelectedIndex); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void SelectedIndex_Should_Be_0_After_Initialize_With_AlwaysSelected() |
|
|
|
{ |
|
|
|
var items = new[] |
|
|
|
{ |
|
|
|
new Item(), |
|
|
|
new Item(), |
|
|
|
}; |
|
|
|
|
|
|
|
var target = new ListBox(); |
|
|
|
target.BeginInit(); |
|
|
|
target.SelectionMode = SelectionMode.Single | SelectionMode.AlwaysSelected; |
|
|
|
target.Items = items; |
|
|
|
target.Template = Template(); |
|
|
|
target.EndInit(); |
|
|
|
|
|
|
|
Assert.Equal(0, target.SelectedIndex); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Setting_SelectedIndex_During_Initialize_Should_Select_Item_When_AlwaysSelected_Is_Used() |
|
|
|
{ |
|
|
|
|