Browse Source

Merge branch 'master' into fixes/1920-renderloop-post

pull/1929/head
danwalmsley 8 years ago
committed by GitHub
parent
commit
5aae02dfea
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/Avalonia.Controls/Generators/ItemContainerGenerator.cs
  2. 2
      src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs
  3. 4
      src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
  4. 1
      src/Skia/Avalonia.Skia/WriteableBitmapImpl.cs
  5. 34
      tests/Avalonia.Controls.UnitTests/ListBoxTests.cs
  6. 26
      tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs

4
src/Avalonia.Controls/Generators/ItemContainerGenerator.cs

@ -15,7 +15,7 @@ namespace Avalonia.Controls.Generators
/// </summary>
public class ItemContainerGenerator : IItemContainerGenerator
{
private Dictionary<int, ItemContainerInfo> _containers = new Dictionary<int, ItemContainerInfo>();
private SortedDictionary<int, ItemContainerInfo> _containers = new SortedDictionary<int, ItemContainerInfo>();
/// <summary>
/// Initializes a new instance of the <see cref="ItemContainerGenerator"/> class.
@ -246,4 +246,4 @@ namespace Avalonia.Controls.Generators
Recycled?.Invoke(this, e);
}
}
}
}

2
src/Avalonia.Controls/Platform/DefaultMenuInteractionHandler.cs

@ -331,7 +331,7 @@ namespace Avalonia.Controls.Platform
{
var item = GetMenuItem(e.Source as IControl);
if (e.MouseButton == MouseButton.Left && item.HasSubMenu == false)
if (e.MouseButton == MouseButton.Left && item?.HasSubMenu == false)
{
Click(item);
e.Handled = true;

4
src/Avalonia.Controls/Primitives/SelectingItemsControl.cs

@ -289,12 +289,12 @@ namespace Avalonia.Controls.Primitives
/// <inheritdoc/>
public override void EndInit()
{
base.EndInit();
if (--_updateCount == 0)
{
UpdateFinished();
}
base.EndInit();
}
/// <summary>

1
src/Skia/Avalonia.Skia/WriteableBitmapImpl.cs

@ -126,6 +126,7 @@ namespace Avalonia.Skia
/// <inheritdoc />
public void Dispose()
{
_bitmap.NotifyPixelsChanged();
_bitmap = null;
}

34
tests/Avalonia.Controls.UnitTests/ListBoxTests.cs

@ -1,16 +1,18 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Collections.ObjectModel;
using System.Linq;
using Avalonia.Collections;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Templates;
using Avalonia.Input;
using Avalonia.Data;
using Avalonia.LogicalTree;
using Avalonia.Styling;
using Avalonia.UnitTests;
using Avalonia.VisualTree;
using Xunit;
using Avalonia.Collections;
namespace Avalonia.Controls.UnitTests
{
@ -170,9 +172,33 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(new Size(100, 10), target.Scroll.Viewport);
}
[Fact]
public void Containers_Correct_After_Clear_Add_Remove()
{
// Issue #1936
var items = new AvaloniaList<string>(Enumerable.Range(0, 11).Select(x => $"Item {x}"));
var target = new ListBox
{
Template = ListBoxTemplate(),
Items = items,
ItemTemplate = new FuncDataTemplate<string>(x => new TextBlock { Width = 20, Height = 10 }),
SelectedIndex = 0,
};
Prepare(target);
items.Clear();
items.AddRange(Enumerable.Range(0, 11).Select(x => $"Item {x}"));
items.Remove("Item 2");
Assert.Equal(
items,
target.Presenter.Panel.Children.Cast<ListBoxItem>().Select(x => (string)x.Content));
}
private FuncControlTemplate ListBoxTemplate()
{
return new FuncControlTemplate<ListBox>(parent =>
return new FuncControlTemplate<ListBox>(parent =>
new ScrollViewer
{
Name = "PART_ScrollViewer",
@ -189,7 +215,7 @@ namespace Avalonia.Controls.UnitTests
private FuncControlTemplate ListBoxItemTemplate()
{
return new FuncControlTemplate<ListBoxItem>(parent =>
return new FuncControlTemplate<ListBoxItem>(parent =>
new ContentPresenter
{
Name = "PART_ContentPresenter",

26
tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs

@ -707,6 +707,26 @@ namespace Avalonia.Controls.UnitTests.Primitives
Assert.True(target.SelectedIndex == 1);
}
[Fact]
public void Binding_With_DelayedBinding_And_Initialization_Where_DataContext_Is_Root_Works()
{
// Test for #1932.
var root = new RootWithItems();
root.BeginInit();
root.DataContext = root;
var target = new ListBox();
target.BeginInit();
root.Child = target;
DelayedBinding.Add(target, ItemsControl.ItemsProperty, new Binding(nameof(RootWithItems.Items)));
DelayedBinding.Add(target, ListBox.SelectedItemProperty, new Binding(nameof(RootWithItems.Selected)));
target.EndInit();
root.EndInit();
Assert.Equal("b", target.SelectedItem);
}
private FuncControlTemplate Template()
{
@ -745,5 +765,11 @@ namespace Avalonia.Controls.UnitTests.Primitives
public IList<Item> Items { get; set; }
public Item SelectedItem { get; set; }
}
private class RootWithItems : TestRoot
{
public List<string> Items { get; set; } = new List<string>() { "a", "b", "c", "d", "e" };
public string Selected { get; set; } = "b";
}
}
}

Loading…
Cancel
Save