Add WheelComboBox

This commit is contained in:
Michael Bucari-Tovo 2022-07-17 00:44:32 -06:00
parent 6a8476c976
commit 4cfe72a63b
4 changed files with 51 additions and 10 deletions

View file

@ -0,0 +1,5 @@
<ComboBox xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="LibationWinForms.AvaloniaUI.Controls.WheelComboBox">
</ComboBox>

View file

@ -0,0 +1,35 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Markup.Xaml;
using Avalonia.Styling;
using System;
using System.Collections;
using System.Linq;
namespace LibationWinForms.AvaloniaUI.Controls
{
public partial class WheelComboBox : ComboBox, IStyleable
{
Type IStyleable.StyleKey => typeof(ComboBox);
public WheelComboBox()
{
InitializeComponent();
}
protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
{
var dir = Math.Sign(e.Delta.Y);
if (dir == 1 && SelectedIndex > 0)
SelectedIndex--;
else if (dir == -1 && SelectedIndex < ItemCount - 1)
SelectedIndex++;
base.OnPointerWheelChanged(e);
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}