From 781f7161e52c81d727c58fd20cd2abaea1c40a46 Mon Sep 17 00:00:00 2001 From: Codex CLI Date: Thu, 28 Aug 2025 04:12:33 -0500 Subject: [PATCH] Handle function insertion on ListBox row taps directly: add Tapped handler to function item Border in DataTemplate and remove global view-level tap handler. Ensures handler is tied to list rows, not the toggle button. --- src/AdvancedCalculator/Views/MainView.axaml | 1 + .../Views/MainView.axaml.cs | 23 ++++--------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/AdvancedCalculator/Views/MainView.axaml b/src/AdvancedCalculator/Views/MainView.axaml index ad2b16e..414d5a7 100644 --- a/src/AdvancedCalculator/Views/MainView.axaml +++ b/src/AdvancedCalculator/Views/MainView.axaml @@ -156,6 +156,7 @@ diff --git a/src/AdvancedCalculator/Views/MainView.axaml.cs b/src/AdvancedCalculator/Views/MainView.axaml.cs index b7faa52..f3fcabc 100644 --- a/src/AdvancedCalculator/Views/MainView.axaml.cs +++ b/src/AdvancedCalculator/Views/MainView.axaml.cs @@ -21,7 +21,6 @@ public partial class MainView : UserControl private MainViewModel? _vm; private ListBox? _historyList; - private bool _functionsTapHandlerAttached; private void OnAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e) { @@ -39,13 +38,7 @@ public partial class MainView : UserControl RoutingStrategies.Tunnel | RoutingStrategies.Bubble); } - // Handle taps anywhere in the functions flyout list items to insert function - if (!_functionsTapHandlerAttached) - { - this.AddHandler(InputElement.TappedEvent, OnFunctionsTapped, - RoutingStrategies.Tunnel | RoutingStrategies.Bubble); - _functionsTapHandlerAttached = true; - } + // Functions list item taps are handled per-row via XAML (OnFunctionsItemTapped) } private void OnDetachedFromVisualTree(object? sender, VisualTreeAttachmentEventArgs e) @@ -59,11 +52,6 @@ public partial class MainView : UserControl _historyList.RemoveHandler(InputElement.TappedEvent, OnHistoryTapped); _historyList = null; } - if (_functionsTapHandlerAttached) - { - this.RemoveHandler(InputElement.TappedEvent, OnFunctionsTapped); - _functionsTapHandlerAttached = false; - } _vm = null; } @@ -98,12 +86,11 @@ public partial class MainView : UserControl } } - private void OnFunctionsTapped(object? sender, TappedEventArgs e) + private void OnFunctionsItemTapped(object? sender, TappedEventArgs e) { - // Find the ListBoxItem the tap originated from, and ensure it's a function item - var srcVisual = e.Source as IVisual; - var container = srcVisual?.FindAncestorOfType(); - if (container?.DataContext is not FunctionDefinitionItem item) + if (sender is not IControl control) + return; + if (control.DataContext is not FunctionDefinitionItem item) return; var vm = DataContext as MainViewModel;