Got function insertion working
This commit is contained in:
parent
2faae1167b
commit
c2bb03044b
2 changed files with 13 additions and 32 deletions
|
@ -160,7 +160,8 @@
|
|||
<ListBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="m:FunctionDefinitionItem">
|
||||
<Border Background="Transparent" Padding="8" MinHeight="36"
|
||||
AutomationProperties.Name="Insert function">
|
||||
AutomationProperties.Name="Insert function"
|
||||
Tapped="OnFunctionsItemTapped">
|
||||
<Grid ColumnDefinitions="*,Auto">
|
||||
<StackPanel>
|
||||
<TextBlock Text="{Binding FunctionName}" FontWeight="Bold"/>
|
||||
|
|
|
@ -95,45 +95,25 @@ public partial class MainView : UserControl
|
|||
|
||||
private void OnFunctionsItemTapped(object? sender, TappedEventArgs e)
|
||||
{
|
||||
if (sender is not Control control)
|
||||
return;
|
||||
if (control.DataContext is not FunctionDefinitionItem item)
|
||||
var lbi = (e.Source as Control)?.FindAncestorOfType<ListBoxItem>();
|
||||
if (lbi?.DataContext is FunctionDefinitionItem item &&
|
||||
_vm?.InsertFunctionCommand.CanExecute(item) == true)
|
||||
{
|
||||
// If attached to panel root, walk up from the source to a ListBoxItem and use its DataContext
|
||||
if (sender is ContentPresenter root && e.Source is ContentPresenter src)
|
||||
{
|
||||
var lbi = src.FindAncestorOfType<ListBoxItem>();
|
||||
if (lbi?.DataContext is not FunctionDefinitionItem rowItem)
|
||||
return;
|
||||
item = rowItem;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var vm = DataContext as MainViewModel;
|
||||
if (vm?.InsertFunctionCommand.CanExecute(item) == true)
|
||||
{
|
||||
vm.InsertFunctionCommand.Execute(item);
|
||||
_vm.InsertFunctionCommand.Execute(item);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnFunctionsFlyoutOpened(object? sender, EventArgs e)
|
||||
{
|
||||
// Flyout content is rendered in a popup; find by name at TopLevel
|
||||
var top = TopLevel.GetTopLevel(this);
|
||||
if (top is null) return;
|
||||
var panel = top.FindControl<Border>("FunctionsPanelRoot");
|
||||
if (panel is null) return;
|
||||
|
||||
// Attach a single tap handler to the flyout content root
|
||||
panel.AddHandler(InputElement.TappedEvent, OnFunctionsItemTapped,
|
||||
private void OnFunctionsFlyoutOpened(object? sender, EventArgs e)
|
||||
{
|
||||
if (sender is Flyout flyout && sender is ContentPresenter presenter)
|
||||
{
|
||||
_functionsPanelRoot = presenter.FindControl<Border>("FunctionsPanelRoot");
|
||||
_functionsPanelRoot?.AddHandler(InputElement.TappedEvent, OnFunctionsItemTapped,
|
||||
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
|
||||
_functionsPanelRoot = panel;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnFunctionsFlyoutClosed(object? sender, EventArgs e)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue