Skip to content

Commit

Permalink
introduced CellTemplateSelector and EdittingTemplateSelector properties
Browse files Browse the repository at this point in the history
  • Loading branch information
w-ahmad committed Jul 9, 2024
1 parent edd7db5 commit 021b95b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
19 changes: 2 additions & 17 deletions src/WinUI.TableView/TableViewCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,27 +155,12 @@ internal async void PrepareForEdit()

internal void SetElement()
{
if (Column is TableViewTemplateColumn templateColumn)
{
ContentTemplate = templateColumn.CellTemplate;
}
else
{
Content = Column.GenerateElement();
}
Content = Column.GenerateElement();
}

private void SetEditingElement()
{
if (Column is TableViewTemplateColumn templateColumn)
{
ContentTemplate = templateColumn.EditingTemplate ?? templateColumn.CellTemplate;
}
else if (Column is not null)
{
Content = Column.GenerateEditingElement();
}

Content = Column.GenerateEditingElement();
if (TableView is not null)
{
TableView.IsEditing = true;
Expand Down
40 changes: 36 additions & 4 deletions src/WinUI.TableView/TableViewTemplateColumn.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

namespace WinUI.TableView;

public class TableViewTemplateColumn : TableViewColumn
{
public override FrameworkElement GenerateElement()
{
return (FrameworkElement)CellTemplate.LoadContent();
var presenter = new ContentPresenter
{
ContentTemplate = CellTemplate,
ContentTemplateSelector = CellTemplateSelector
};

return presenter;
}

public override FrameworkElement GenerateEditingElement()
{
return EditingTemplate is not null ? (FrameworkElement)EditingTemplate.LoadContent() : (FrameworkElement)CellTemplate.LoadContent();
if (EditingTemplate is not null || EditingTemplateSelector is not null)
{
var presenter = new ContentPresenter
{
ContentTemplate = EditingTemplate,
ContentTemplateSelector = EditingTemplateSelector
};

return presenter;
}

return GenerateElement();
}

public DataTemplate CellTemplate
Expand All @@ -20,12 +38,26 @@ public DataTemplate CellTemplate
set => SetValue(CellTemplateProperty, value);
}

public DataTemplateSelector CellTemplateSelector
{
get => (DataTemplateSelector)GetValue(CellTemplateSelectorProperty);
set => SetValue(CellTemplateSelectorProperty, value);
}

public DataTemplate EditingTemplate
{
get => (DataTemplate)GetValue(EditingTemplateProperty);
set => SetValue(EditingTemplateProperty, value);
}

public static readonly DependencyProperty CellTemplateProperty = DependencyProperty.Register(nameof(CellTemplate), typeof(DataTemplate), typeof(TableViewTemplateColumn), new PropertyMetadata(null));
public static readonly DependencyProperty EditingTemplateProperty = DependencyProperty.Register(nameof(EditingTemplate), typeof(DataTemplate), typeof(TableViewTemplateColumn), new PropertyMetadata(null));
public DataTemplateSelector EditingTemplateSelector
{
get => (DataTemplateSelector)GetValue(EditingTemplateSelectorProperty);
set => SetValue(EditingTemplateSelectorProperty, value);
}

public static readonly DependencyProperty CellTemplateProperty = DependencyProperty.Register(nameof(CellTemplate), typeof(DataTemplate), typeof(TableViewTemplateColumn), new PropertyMetadata(default));
public static readonly DependencyProperty CellTemplateSelectorProperty = DependencyProperty.Register(nameof(CellTemplateSelector), typeof(DataTemplateSelector), typeof(TableViewTemplateColumn), new PropertyMetadata(default));
public static readonly DependencyProperty EditingTemplateProperty = DependencyProperty.Register(nameof(EditingTemplate), typeof(DataTemplate), typeof(TableViewTemplateColumn), new PropertyMetadata(default));
public static readonly DependencyProperty EditingTemplateSelectorProperty = DependencyProperty.Register(nameof(EditingTemplateSelector), typeof(DataTemplateSelector), typeof(TableViewTemplateColumn), new PropertyMetadata(default));
}

0 comments on commit 021b95b

Please sign in to comment.