Browse Source

Expose IScrollable in ListBox.

To allow programmatic control of the ListBox's scroll.
pull/554/head
Steven Kirk 11 years ago
parent
commit
e930c35882
  1. 14
      src/Avalonia.Controls/ListBox.cs
  2. 2
      src/Avalonia.Themes.Default/ListBox.xaml

14
src/Avalonia.Controls/ListBox.cs

@ -2,13 +2,10 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Collections;
using System.Collections.Generic;
using Avalonia.Collections;
using Avalonia.Controls.Generators;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Input;
using Avalonia.Interactivity;
namespace Avalonia.Controls
{
@ -43,6 +40,11 @@ namespace Avalonia.Controls
ItemsPanelProperty.OverrideDefaultValue<ListBox>(DefaultPanel);
}
/// <summary>
/// Gets the scroll information for the <see cref="ListBox"/>.
/// </summary>
public IScrollable Scroll { get; set; }
/// <inheritdoc/>
public new IList SelectedItems => base.SelectedItems;
@ -90,5 +92,11 @@ namespace Avalonia.Controls
(e.InputModifiers & InputModifiers.Control) != 0);
}
}
protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
{
base.OnTemplateApplied(e);
Scroll = e.NameScope.Find<IScrollable>("PART_ScrollViewer");
}
}
}

2
src/Avalonia.Themes.Default/ListBox.xaml

@ -7,7 +7,7 @@
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer>
<ScrollViewer Name="PART_ScrollViewer">
<ItemsPresenter Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}"

Loading…
Cancel
Save