Browse Source
Merge branch 'master' into fix-nested-popups
pull/2928/head
Steven Kirk
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
42 additions and
8 deletions
-
src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
-
src/Avalonia.Styling/Controls/ResourceNodeExtensions.cs
-
src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/DynamicResourceExtension.cs
-
src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StaticResourceExtension.cs
-
tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs
|
|
@ -304,6 +304,11 @@ namespace Avalonia.Controls.Primitives |
|
|
{ |
|
|
{ |
|
|
base.ItemsCollectionChanged(sender, e); |
|
|
base.ItemsCollectionChanged(sender, e); |
|
|
|
|
|
|
|
|
|
|
|
if (_updateCount > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
switch (e.Action) |
|
|
switch (e.Action) |
|
|
{ |
|
|
{ |
|
|
case NotifyCollectionChangedAction.Add: |
|
|
case NotifyCollectionChangedAction.Add: |
|
|
@ -1071,13 +1076,20 @@ namespace Avalonia.Controls.Primitives |
|
|
|
|
|
|
|
|
private void UpdateFinished() |
|
|
private void UpdateFinished() |
|
|
{ |
|
|
{ |
|
|
if (_updateSelectedIndex != int.MinValue) |
|
|
if (_updateSelectedItem != null) |
|
|
{ |
|
|
{ |
|
|
SelectedIndex = _updateSelectedIndex; |
|
|
SelectedItem = _updateSelectedItem; |
|
|
} |
|
|
} |
|
|
else if (_updateSelectedItem != null) |
|
|
else |
|
|
{ |
|
|
{ |
|
|
SelectedItem = _updateSelectedItem; |
|
|
if (ItemCount == 0 && SelectedIndex != -1) |
|
|
|
|
|
{ |
|
|
|
|
|
SelectedIndex = -1; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
SelectedIndex = _updateSelectedIndex != int.MinValue ? _updateSelectedIndex : 0; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -3,7 +3,7 @@ using Avalonia.Reactive; |
|
|
|
|
|
|
|
|
namespace Avalonia.Controls |
|
|
namespace Avalonia.Controls |
|
|
{ |
|
|
{ |
|
|
public static class ResourceProviderExtensions |
|
|
public static class ResourceNodeExtensions |
|
|
{ |
|
|
{ |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Finds the specified resource by searching up the logical tree and then global styles.
|
|
|
/// Finds the specified resource by searching up the logical tree and then global styles.
|
|
|
@ -18,7 +18,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions |
|
|
{ |
|
|
{ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public DynamicResourceExtension(string resourceKey) |
|
|
public DynamicResourceExtension(object resourceKey) |
|
|
{ |
|
|
{ |
|
|
ResourceKey = resourceKey; |
|
|
ResourceKey = resourceKey; |
|
|
} |
|
|
} |
|
|
|
|
|
@ -16,12 +16,12 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions |
|
|
{ |
|
|
{ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public StaticResourceExtension(string resourceKey) |
|
|
public StaticResourceExtension(object resourceKey) |
|
|
{ |
|
|
{ |
|
|
ResourceKey = resourceKey; |
|
|
ResourceKey = resourceKey; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public string ResourceKey { get; set; } |
|
|
public object ResourceKey { get; set; } |
|
|
|
|
|
|
|
|
public object ProvideValue(IServiceProvider serviceProvider) |
|
|
public object ProvideValue(IServiceProvider serviceProvider) |
|
|
{ |
|
|
{ |
|
|
|
|
|
@ -109,6 +109,28 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
Assert.True(items[1].IsSelected); |
|
|
Assert.True(items[1].IsSelected); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
|
|
public void Setting_SelectedIndex_During_Initialize_Should_Select_Item_When_AlwaysSelected_Is_Used() |
|
|
|
|
|
{ |
|
|
|
|
|
var listBox = new ListBox |
|
|
|
|
|
{ |
|
|
|
|
|
SelectionMode = SelectionMode.Single | SelectionMode.AlwaysSelected |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
listBox.BeginInit(); |
|
|
|
|
|
|
|
|
|
|
|
listBox.SelectedIndex = 1; |
|
|
|
|
|
var items = new AvaloniaList<string>(); |
|
|
|
|
|
listBox.Items = items; |
|
|
|
|
|
items.Add("A"); |
|
|
|
|
|
items.Add("B"); |
|
|
|
|
|
items.Add("C"); |
|
|
|
|
|
|
|
|
|
|
|
listBox.EndInit(); |
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal("B", listBox.SelectedItem); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void Setting_SelectedIndex_Before_ApplyTemplate_Should_Set_Item_IsSelected_True() |
|
|
public void Setting_SelectedIndex_Before_ApplyTemplate_Should_Set_Item_IsSelected_True() |
|
|
{ |
|
|
{ |
|
|
|