fix: fix touch mode.

This commit is contained in:
rabbitism
2024-03-27 16:24:52 +08:00
parent 35128295b3
commit 0f5d41e17d
2 changed files with 33 additions and 22 deletions

View File

@@ -178,16 +178,7 @@ public class MultiComboBox: SelectingItemsControl, IInnerContentControl
}
}
}
public void SelectAll()
{
this.SelectedItems?.Clear();
foreach (var item in Items)
{
this.SelectedItems?.Add(item);
}
}
protected override void OnUnloaded(RoutedEventArgs e)
{
base.OnUnloaded(e);

View File

@@ -11,6 +11,8 @@ namespace Ursa.Controls;
public class MultiComboBoxItem: ContentControl
{
private MultiComboBox? _parent;
private static readonly Point s_invalidPoint = new (double.NaN, double.NaN);
private Point _pointerDownPoint = s_invalidPoint;
public static readonly StyledProperty<bool> IsSelectedProperty = AvaloniaProperty.Register<MultiComboBoxItem, bool>(
nameof(IsSelected));
@@ -43,16 +45,6 @@ public class MultiComboBoxItem: ContentControl
}
}
public MultiComboBoxItem()
{
this.GetObservable(IsFocusedProperty).Subscribe(a=> {
if (a)
{
(Parent as MultiComboBox)?.ItemFocused(this);
}
});
}
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
@@ -64,14 +56,42 @@ public class MultiComboBoxItem: ContentControl
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
base.OnPointerPressed(e);
_pointerDownPoint = e.GetPosition(this);
if (e.Handled)
{
return;
}
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
{
this.IsSelected = !this.IsSelected;
e.Handled = true;
var p = e.GetCurrentPoint(this);
if (p.Properties.PointerUpdateKind is PointerUpdateKind.LeftButtonPressed
or PointerUpdateKind.RightButtonPressed)
{
if (p.Pointer.Type == PointerType.Mouse)
{
this.IsSelected = !this.IsSelected;
e.Handled = true;
}
else
{
_pointerDownPoint = p.Position;
}
}
}
}
protected override void OnPointerReleased(PointerReleasedEventArgs e)
{
base.OnPointerReleased(e);
if (!e.Handled && !double.IsNaN(_pointerDownPoint.X) &&
e.InitialPressMouseButton is MouseButton.Left or MouseButton.Right)
{
var point = e.GetCurrentPoint(this);
if (new Rect(Bounds.Size).ContainsExclusive(point.Position))
{
this.IsSelected = !this.IsSelected;
e.Handled = true;
}
}
}
}