Skip to content

Commit 7952c2f

Browse files
committed
fix NumberBoxColumn value commit issue
1 parent 31ba034 commit 7952c2f

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/Columns/TableViewNumberColumn.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.UI.Xaml;
22
using Microsoft.UI.Xaml.Controls;
3+
using WinUI.TableView.Extensions;
34

45
namespace WinUI.TableView;
56

@@ -65,6 +66,8 @@ protected internal override void EndCellEditing(TableViewCell cell, object? data
6566
{
6667
if (editAction == TableViewEditAction.Commit)
6768
{
69+
numberBox.UpdateValue();
70+
6871
var bindingExpression = numberBox.GetBindingExpression(NumberBox.ValueProperty);
6972
bindingExpression?.UpdateSource();
7073
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using CommunityToolkit.WinUI;
2+
using Microsoft.UI.Xaml.Controls;
3+
4+
namespace WinUI.TableView.Extensions;
5+
6+
/// <summary>
7+
/// Provides extension methods for FrameworkElements.
8+
/// </summary>
9+
internal static class FrameworkElementExtensions
10+
{
11+
/// <summary>
12+
/// NumberBox does not update its Text property automatically until it loses focus in some cases.
13+
/// This method forces the NumberBox to update its Text property.
14+
/// </summary>
15+
/// <param name="numberBox">The NumberBox to update its value.</param>
16+
internal static void UpdateValue(this NumberBox numberBox)
17+
{
18+
var inputTextBox = numberBox.FindDescendant<TextBox>(x => x.Name is "InputBox");
19+
20+
if (inputTextBox is not null && inputTextBox.Text != numberBox.Text)
21+
{
22+
numberBox.Text = inputTextBox.Text;
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)