Use ListBoxItem taps to insert functions: remove inner Button from functions list template, keep item DataContext as FunctionDefinitionItem, and handle tap in code-behind by executing InsertFunctionCommand with the tapped item. Mirror history list clipboard pattern. Name flyout root for clarity.
This commit is contained in:
parent
ad8e178484
commit
8a5a50fcaa
2 changed files with 33 additions and 6 deletions
|
@ -21,6 +21,7 @@ public partial class MainView : UserControl
|
|||
|
||||
private MainViewModel? _vm;
|
||||
private ListBox? _historyList;
|
||||
private bool _functionsTapHandlerAttached;
|
||||
|
||||
private void OnAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
|
@ -37,6 +38,14 @@ public partial class MainView : UserControl
|
|||
_historyList.AddHandler(InputElement.TappedEvent, OnHistoryTapped,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDetachedFromVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
|
||||
|
@ -50,6 +59,11 @@ public partial class MainView : UserControl
|
|||
_historyList.RemoveHandler(InputElement.TappedEvent, OnHistoryTapped);
|
||||
_historyList = null;
|
||||
}
|
||||
if (_functionsTapHandlerAttached)
|
||||
{
|
||||
this.RemoveHandler(InputElement.TappedEvent, OnFunctionsTapped);
|
||||
_functionsTapHandlerAttached = false;
|
||||
}
|
||||
_vm = null;
|
||||
}
|
||||
|
||||
|
@ -83,4 +97,20 @@ public partial class MainView : UserControl
|
|||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnFunctionsTapped(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<ListBoxItem>();
|
||||
if (container?.DataContext is not FunctionDefinitionItem item)
|
||||
return;
|
||||
|
||||
var vm = DataContext as MainViewModel;
|
||||
if (vm?.InsertFunctionCommand.CanExecute(item) == true)
|
||||
{
|
||||
vm.InsertFunctionCommand.Execute(item);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue