Browse Source

Merge branch 'master' into fixes/PathMarkupParser

pull/1661/head
Benedikt Schroeder 8 years ago
committed by GitHub
parent
commit
384577e02e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      src/Avalonia.Controls/Presenters/CarouselPresenter.cs
  2. 3
      src/Avalonia.Controls/ToolTip.cs
  3. 35
      tests/Avalonia.Controls.UnitTests/CarouselTests.cs

16
src/Avalonia.Controls/Presenters/CarouselPresenter.cs

@ -126,7 +126,21 @@ namespace Avalonia.Controls.Presenters
generator.Clear();
Panel.Children.RemoveAll(containers.Select(x => x.ContainerControl));
MoveToPage(-1, SelectedIndex >= 0 ? SelectedIndex : 0);
var newIndex = SelectedIndex;
if(SelectedIndex < 0)
{
if(Items != null && Items.Count() > 0)
{
newIndex = 0;
}
else
{
newIndex = -1;
}
}
MoveToPage(-1, newIndex);
}
break;
}

3
src/Avalonia.Controls/ToolTip.cs

@ -234,11 +234,12 @@ namespace Avalonia.Controls
{
Close();
_popup = new PopupRoot { Content = this };
_popup = new PopupRoot { Content = this, };
((ISetLogicalParent)_popup).SetParent(control);
_popup.Position = Popup.GetPosition(control, GetPlacement(control), _popup,
GetHorizontalOffset(control), GetVerticalOffset(control));
_popup.Show();
_popup.SnapInsideScreenEdges();
}
private void Close()

35
tests/Avalonia.Controls.UnitTests/CarouselTests.cs

@ -170,6 +170,41 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal("Bar", ((TextBlock)child).Text);
}
[Fact]
public void Selected_Index_Changes_To_When_Items_Assigned_Null()
{
var items = new ObservableCollection<string>
{
"Foo",
"Bar",
"FooBar"
};
var target = new Carousel
{
Template = new FuncControlTemplate<Carousel>(CreateTemplate),
Items = items,
IsVirtualized = false
};
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
Assert.Single(target.GetLogicalChildren());
var child = target.GetLogicalChildren().Single();
Assert.IsType<TextBlock>(child);
Assert.Equal("Foo", ((TextBlock)child).Text);
target.Items = null;
var numChildren = target.GetLogicalChildren().Count();
Assert.Equal(0, numChildren);
Assert.Equal(-1, target.SelectedIndex);
}
[Fact]
public void Selected_Index_Is_Maintained_Carousel_Created_With_Non_Zero_SelectedIndex()
{

Loading…
Cancel
Save