diff --git a/Avalonia.v3.ncrunchsolution b/Avalonia.v3.ncrunchsolution
index bef7e45524..afce1018ec 100644
--- a/Avalonia.v3.ncrunchsolution
+++ b/Avalonia.v3.ncrunchsolution
@@ -6,6 +6,9 @@
src\Avalonia.Build.Tasks\bin\Debug\netstandard2.0\Mono.Cecil.dll
True
+
+ RunApiCompat = false
+
.ncrunch
True
diff --git a/build/SkiaSharp.props b/build/SkiaSharp.props
index d7d04c7971..f2e7df36cd 100644
--- a/build/SkiaSharp.props
+++ b/build/SkiaSharp.props
@@ -1,6 +1,6 @@
-
-
+
+
diff --git a/samples/ControlCatalog/MainView.xaml b/samples/ControlCatalog/MainView.xaml
index efc90357ed..790813fda0 100644
--- a/samples/ControlCatalog/MainView.xaml
+++ b/samples/ControlCatalog/MainView.xaml
@@ -45,7 +45,10 @@
-
+
+
+
diff --git a/samples/ControlCatalog/Pages/ListBoxPage.xaml b/samples/ControlCatalog/Pages/ListBoxPage.xaml
index edf3d41bf5..3521ad71a9 100644
--- a/samples/ControlCatalog/Pages/ListBoxPage.xaml
+++ b/samples/ControlCatalog/Pages/ListBoxPage.xaml
@@ -1,35 +1,25 @@
-
- ListBox
- Hosts a collection of ListBoxItem.
-
-
-
-
-
-
-
-
-
-
-
-
- Single
- Multiple
- Toggle
- AlwaysSelected
-
-
+
+
+ ListBox
+ Hosts a collection of ListBoxItem.
-
+
+ Multiple
+ Toggle
+ AlwaysSelected
+ AutoScrollToSelectedItem
+
+
+
+
+
+
+
+
diff --git a/samples/ControlCatalog/ViewModels/ListBoxPageViewModel.cs b/samples/ControlCatalog/ViewModels/ListBoxPageViewModel.cs
index d088576998..f75bc32105 100644
--- a/samples/ControlCatalog/ViewModels/ListBoxPageViewModel.cs
+++ b/samples/ControlCatalog/ViewModels/ListBoxPageViewModel.cs
@@ -10,22 +10,39 @@ namespace ControlCatalog.ViewModels
{
public class ListBoxPageViewModel : ReactiveObject
{
+ private bool _multiple;
+ private bool _toggle;
+ private bool _alwaysSelected;
+ private bool _autoScrollToSelectedItem = true;
private int _counter;
- private SelectionMode _selectionMode;
+ private ObservableAsPropertyHelper _selectionMode;
public ListBoxPageViewModel()
{
Items = new ObservableCollection(Enumerable.Range(1, 10000).Select(i => GenerateItem()));
+
Selection = new SelectionModel();
Selection.Select(1);
+ _selectionMode = this.WhenAnyValue(
+ x => x.Multiple,
+ x => x.Toggle,
+ x => x.AlwaysSelected,
+ (m, t, a) =>
+ (m ? SelectionMode.Multiple : 0) |
+ (t ? SelectionMode.Toggle : 0) |
+ (a ? SelectionMode.AlwaysSelected : 0))
+ .ToProperty(this, x => x.SelectionMode);
+
AddItemCommand = ReactiveCommand.Create(() => Items.Add(GenerateItem()));
RemoveItemCommand = ReactiveCommand.Create(() =>
{
- while (Selection.Count > 0)
+ var items = Selection.SelectedItems.ToList();
+
+ foreach (var item in items)
{
- Items.Remove(Selection.SelectedItems.First());
+ Items.Remove(item);
}
});
@@ -42,25 +59,37 @@ namespace ControlCatalog.ViewModels
}
public ObservableCollection Items { get; }
-
public SelectionModel Selection { get; }
+ public SelectionMode SelectionMode => _selectionMode.Value;
- public ReactiveCommand AddItemCommand { get; }
+ public bool Multiple
+ {
+ get => _multiple;
+ set => this.RaiseAndSetIfChanged(ref _multiple, value);
+ }
- public ReactiveCommand RemoveItemCommand { get; }
+ public bool Toggle
+ {
+ get => _toggle;
+ set => this.RaiseAndSetIfChanged(ref _toggle, value);
+ }
- public ReactiveCommand SelectRandomItemCommand { get; }
+ public bool AlwaysSelected
+ {
+ get => _alwaysSelected;
+ set => this.RaiseAndSetIfChanged(ref _alwaysSelected, value);
+ }
- public SelectionMode SelectionMode
+ public bool AutoScrollToSelectedItem
{
- get => _selectionMode;
- set
- {
- Selection.Clear();
- this.RaiseAndSetIfChanged(ref _selectionMode, value);
- }
+ get => _autoScrollToSelectedItem;
+ set => this.RaiseAndSetIfChanged(ref _autoScrollToSelectedItem, value);
}
+ public ReactiveCommand AddItemCommand { get; }
+ public ReactiveCommand RemoveItemCommand { get; }
+ public ReactiveCommand SelectRandomItemCommand { get; }
+
private string GenerateItem() => $"Item {_counter++.ToString()}";
}
}
diff --git a/src/Avalonia.Controls/ListBox.cs b/src/Avalonia.Controls/ListBox.cs
index f7e86d697a..d1b8038581 100644
--- a/src/Avalonia.Controls/ListBox.cs
+++ b/src/Avalonia.Controls/ListBox.cs
@@ -163,6 +163,7 @@ namespace Avalonia.Controls
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
+ base.OnApplyTemplate(e);
Scroll = e.NameScope.Find("PART_ScrollViewer");
}
}
diff --git a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
index 5f8c5da2f8..c954f9fd4a 100644
--- a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
+++ b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
@@ -6,7 +6,6 @@ using System.ComponentModel;
using System.Linq;
using Avalonia.Controls.Generators;
using Avalonia.Controls.Selection;
-using Avalonia.Controls.Utils;
using Avalonia.Data;
using Avalonia.Input;
using Avalonia.Input.Platform;
@@ -70,8 +69,8 @@ namespace Avalonia.Controls.Primitives
///
/// Defines the property.
///
- protected static readonly DirectProperty SelectedItemsProperty =
- AvaloniaProperty.RegisterDirect(
+ protected static readonly DirectProperty SelectedItemsProperty =
+ AvaloniaProperty.RegisterDirect(
nameof(SelectedItems),
o => o.SelectedItems,
(o, v) => o.SelectedItems = v);
@@ -111,12 +110,13 @@ namespace Avalonia.Controls.Primitives
RoutingStrategies.Bubble);
private static readonly IList Empty = Array.Empty