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>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate x:DataType="m:FunctionDefinitionItem">
|
<DataTemplate x:DataType="m:FunctionDefinitionItem">
|
||||||
<Border Background="Transparent" Padding="8" MinHeight="36"
|
<Border Background="Transparent" Padding="8" MinHeight="36"
|
||||||
AutomationProperties.Name="Insert function">
|
AutomationProperties.Name="Insert function"
|
||||||
|
Tapped="OnFunctionsItemTapped">
|
||||||
<Grid ColumnDefinitions="*,Auto">
|
<Grid ColumnDefinitions="*,Auto">
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<TextBlock Text="{Binding FunctionName}" FontWeight="Bold"/>
|
<TextBlock Text="{Binding FunctionName}" FontWeight="Bold"/>
|
||||||
|
|
|
@ -95,45 +95,25 @@ public partial class MainView : UserControl
|
||||||
|
|
||||||
private void OnFunctionsItemTapped(object? sender, TappedEventArgs e)
|
private void OnFunctionsItemTapped(object? sender, TappedEventArgs e)
|
||||||
{
|
{
|
||||||
if (sender is not Control control)
|
var lbi = (e.Source as Control)?.FindAncestorOfType<ListBoxItem>();
|
||||||
return;
|
if (lbi?.DataContext is FunctionDefinitionItem item &&
|
||||||
if (control.DataContext is not FunctionDefinitionItem item)
|
_vm?.InsertFunctionCommand.CanExecute(item) == true)
|
||||||
{
|
{
|
||||||
// If attached to panel root, walk up from the source to a ListBoxItem and use its DataContext
|
_vm.InsertFunctionCommand.Execute(item);
|
||||||
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);
|
|
||||||
e.Handled = true;
|
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
|
private void OnFunctionsFlyoutOpened(object? sender, EventArgs e)
|
||||||
panel.AddHandler(InputElement.TappedEvent, OnFunctionsItemTapped,
|
{
|
||||||
|
if (sender is Flyout flyout && sender is ContentPresenter presenter)
|
||||||
|
{
|
||||||
|
_functionsPanelRoot = presenter.FindControl<Border>("FunctionsPanelRoot");
|
||||||
|
_functionsPanelRoot?.AddHandler(InputElement.TappedEvent, OnFunctionsItemTapped,
|
||||||
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
|
RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
|
||||||
_functionsPanelRoot = panel;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnFunctionsFlyoutClosed(object? sender, EventArgs e)
|
private void OnFunctionsFlyoutClosed(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue