Skip to content

Commit 5f42a28

Browse files
committed
fix: restore Command bindings on table editor buttons, remove Click handler workaround
1 parent e295d36 commit 5f42a28

2 files changed

Lines changed: 4 additions & 16 deletions

File tree

src/SharpFM/Schema/Editor/TableEditorControl.axaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
<Button Grid.Column="2"
2626
Margin="8,0,4,0"
2727
Content="+ Add Field"
28-
x:Name="addFieldButton" />
28+
Command="{Binding AddFieldCommand}" />
2929
<Button Grid.Column="3"
3030
Content="Remove"
31-
x:Name="removeFieldButton" />
31+
Command="{Binding RemoveFieldCommand}" />
3232
<Button Grid.Column="4"
3333
Margin="8,0,0,0"
3434
Content="Edit Calculation..."
35-
x:Name="editCalcButton" />
35+
Command="{Binding EditCalculationCommand}" />
3636
</Grid>
3737
</Border>
3838

src/SharpFM/Schema/Editor/TableEditorControl.axaml.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using Avalonia.Controls;
33
using Avalonia.Input;
4-
using Avalonia.Interactivity;
54
using SharpFM.Schema.Model;
65

76
namespace SharpFM.Schema.Editor;
@@ -14,23 +13,12 @@ public partial class TableEditorControl : UserControl
1413
public TableEditorControl()
1514
{
1615
InitializeComponent();
17-
18-
var addBtn = this.FindControl<Button>("addFieldButton");
19-
var removeBtn = this.FindControl<Button>("removeFieldButton");
20-
var calcBtn = this.FindControl<Button>("editCalcButton");
21-
22-
if (addBtn != null) addBtn.Click += (_, _) => GetVm()?.AddField();
23-
if (removeBtn != null) removeBtn.Click += (_, _) => GetVm()?.RemoveSelectedField();
24-
if (calcBtn != null) calcBtn.Click += (_, _) => GetVm()?.OpenCalculationEditor();
25-
2616
KeyDown += OnKeyDown;
2717
}
2818

29-
private TableEditorViewModel? GetVm() => DataContext as TableEditorViewModel;
30-
3119
private void OnKeyDown(object? sender, KeyEventArgs e)
3220
{
33-
if (e.Key == Key.Delete && GetVm() is { } vm)
21+
if (e.Key == Key.Delete && DataContext is TableEditorViewModel vm)
3422
{
3523
vm.RemoveSelectedField();
3624
e.Handled = true;

0 commit comments

Comments
 (0)