-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from w-ahmad/feature/gridlines
Add Horizontal and Vertical Grid Lines
- Loading branch information
Showing
16 changed files
with
787 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,69 @@ | ||
using Microsoft.UI.Xaml.Controls; | ||
using CommunityToolkit.WinUI; | ||
using Microsoft.UI; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Media; | ||
using Microsoft.UI.Xaml.Shapes; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace WinUI.TableView; | ||
|
||
public class TableViewCellsPresenter : StackPanel | ||
public class TableViewCellsPresenter : Control | ||
{ | ||
private StackPanel? _stackPanel; | ||
private Rectangle? _v_gridLine; | ||
private Rectangle? _h_gridLine; | ||
|
||
public TableViewCellsPresenter() | ||
{ | ||
Orientation = Orientation.Horizontal; | ||
DefaultStyleKey = typeof(TableViewCellsPresenter); | ||
} | ||
|
||
protected override void OnApplyTemplate() | ||
{ | ||
base.OnApplyTemplate(); | ||
|
||
_stackPanel = GetTemplateChild("StackPanel") as StackPanel; | ||
_v_gridLine = GetTemplateChild("VerticalGridLine") as Rectangle; | ||
_h_gridLine = GetTemplateChild("HorizontalGridLine") as Rectangle; | ||
|
||
TableViewRow = this.FindAscendant<TableViewRow>(); | ||
TableView = TableViewRow?.TableView; | ||
|
||
EnsureGridLines(); | ||
} | ||
|
||
internal void EnsureGridLines() | ||
{ | ||
if (TableView is null) return; | ||
|
||
if (_h_gridLine is not null) | ||
{ | ||
_h_gridLine.Fill = TableView.HorizontalGridLinesStroke; | ||
_h_gridLine.Height = TableView.HorizontalGridLinesStrokeThickness; | ||
_h_gridLine.Visibility = TableView.GridLinesVisibility is TableViewGridLinesVisibility.All or TableViewGridLinesVisibility.Horizontal | ||
? Visibility.Visible : Visibility.Collapsed; | ||
|
||
if (_v_gridLine is not null) | ||
{ | ||
_v_gridLine.Fill = TableView.HeaderGridLinesVisibility is TableViewGridLinesVisibility.All or TableViewGridLinesVisibility.Vertical | ||
? TableView.VerticalGridLinesStroke : new SolidColorBrush(Colors.Transparent); | ||
_v_gridLine.Width = TableView.VerticalGridLinesStrokeThickness; | ||
_v_gridLine.Visibility = TableView.HeaderGridLinesVisibility is TableViewGridLinesVisibility.All or TableViewGridLinesVisibility.Vertical | ||
|| TableView.GridLinesVisibility is TableViewGridLinesVisibility.All or TableViewGridLinesVisibility.Vertical | ||
? Visibility.Visible : Visibility.Collapsed; | ||
} | ||
} | ||
|
||
foreach (var cell in Cells) | ||
{ | ||
cell.EnsureGridLines(); | ||
} | ||
} | ||
|
||
public IList<TableViewCell> Cells => Children.OfType<TableViewCell>().ToList().AsReadOnly(); | ||
internal UIElementCollection Children => _stackPanel?.Children!; | ||
public IList<TableViewCell> Cells => _stackPanel?.Children.OfType<TableViewCell>().ToList()!; | ||
public TableViewRow? TableViewRow { get; private set; } | ||
public TableView? TableView { get; private set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.