Skip to content

Commit b570da5

Browse files
committed
use binding to get display text
1 parent d2589fe commit b570da5

1 file changed

Lines changed: 4 additions & 17 deletions

File tree

src/Columns/TableViewComboBoxColumn.cs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public override FrameworkElement GenerateElement(TableViewCell cell, object? dat
3333

3434
if (!string.IsNullOrEmpty(DisplayMemberPath))
3535
{
36-
textBlock.Text = GetDisplayText(dataItem);
36+
textBlock.SetBinding(FrameworkElement.DataContextProperty, Binding);
37+
textBlock.SetBinding(TextBlock.TextProperty, new Binding { Path = new PropertyPath(DisplayMemberPath) });
3738
}
3839
else
3940
{
@@ -43,22 +44,6 @@ public override FrameworkElement GenerateElement(TableViewCell cell, object? dat
4344
return textBlock;
4445
}
4546

46-
/// <summary>
47-
/// Gets display text based on <see cref="DisplayMemberPath"/>.
48-
/// </summary>
49-
private string? GetDisplayText(object? dataItem)
50-
{
51-
if (GetCellContent(dataItem) is { } value)
52-
{
53-
_funcCompiledDisplayMemberPath ??= value.GetFuncCompiledPropertyPath(DisplayMemberPath!);
54-
55-
if (_funcCompiledDisplayMemberPath is not null)
56-
return _funcCompiledDisplayMemberPath(value) as string;
57-
}
58-
59-
return default;
60-
}
61-
6247
/// <summary>
6348
/// Generates a ComboBox element for editing the cell.
6449
/// </summary>
@@ -84,6 +69,8 @@ public override FrameworkElement GenerateEditingElement(TableViewCell cell, obje
8469
comboBox.SetBinding(Selector.SelectedValueProperty, SelectedValueBinding);
8570
}
8671

72+
comboBox.GetBindingExpression(Selector.SelectedItemProperty)?.UpdateSource();
73+
8774
return comboBox;
8875
}
8976

0 commit comments

Comments
 (0)