mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-10-16 23:49:19 +02:00
Find the list item under the pointer with FindAncestorOfType
This commit is contained in:
@@ -5,6 +5,7 @@ using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.VisualTree;
|
||||
|
||||
using StarterNG.Classes;
|
||||
using StarterNG.Domain;
|
||||
@@ -113,10 +114,7 @@ public sealed class ConsistDragging
|
||||
if (!e.GetCurrentPoint(vehicleListBox).Properties.IsLeftButtonPressed)
|
||||
return;
|
||||
|
||||
var hit = e.Source as Control;
|
||||
while (hit != null && hit is not ListBoxItem)
|
||||
hit = hit.Parent as Control;
|
||||
if (hit is ListBoxItem { Tag: VehicleTexture texture })
|
||||
if ((e.Source as Visual).FindAncestorOfType<ListBoxItem>(includeSelf: true) is { Tag: VehicleTexture texture })
|
||||
ArmVehicleDrag(e, vehicleListBox, texture);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ using Avalonia.Layout;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Threading;
|
||||
using Avalonia.VisualTree;
|
||||
|
||||
using StarterNG.Classes;
|
||||
using StarterNG.Domain;
|
||||
@@ -363,11 +364,8 @@ public sealed class VehicleBrowser
|
||||
|
||||
private void List_OnContextRequested(object? sender, ContextRequestedEventArgs e)
|
||||
{
|
||||
var hit = e.Source as Control;
|
||||
while (hit != null && hit is not ListBoxItem)
|
||||
hit = hit.Parent as Control;
|
||||
|
||||
if (hit is not ListBoxItem { Tag: VehicleTexture texture })
|
||||
if ((e.Source as Visual).FindAncestorOfType<ListBoxItem>(includeSelf: true) is not
|
||||
{ Tag: VehicleTexture texture } hit)
|
||||
return;
|
||||
|
||||
BuildBrowserMenu(texture, hit).Open(hit);
|
||||
|
||||
@@ -16,6 +16,7 @@ using Avalonia.Interactivity;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.VisualTree;
|
||||
using StarterNG.Classes;
|
||||
using StarterNG.Domain;
|
||||
using StarterNG.Application;
|
||||
@@ -103,11 +104,7 @@ public partial class Scenarios : UserControl
|
||||
// A right click picks the scenery under it, so the menu speaks of that one.
|
||||
private void SceneryList_OnContextRequested(object? sender, ContextRequestedEventArgs e)
|
||||
{
|
||||
var hit = e.Source as Control;
|
||||
while (hit is not null and not TreeViewItem)
|
||||
hit = hit.Parent as Control;
|
||||
|
||||
if (hit is TreeViewItem { Tag: int } item)
|
||||
if ((e.Source as Visual).FindAncestorOfType<TreeViewItem>(includeSelf: true) is { Tag: int } item)
|
||||
sceneryList.SelectedItem = item;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user