Skip to content

Commit a0ee89f

Browse files
committed
refactored TableViewColumnHeader initialization logic
1 parent ab7c8a4 commit a0ee89f

3 files changed

Lines changed: 24 additions & 15 deletions

File tree

src/TableViewColumnHeader.OptionsFlyoutViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public IList<TableViewFilterItem> FilterItems
128128
/// <summary>
129129
/// Sets the state of the select all checkbox.
130130
/// </summary>
131-
private void SetSelectAllCheckBoxState()
131+
internal void SetSelectAllCheckBoxState()
132132
{
133133
if (ColumnHeader._selectAllCheckBox is null || !_canSetState)
134134
{

src/TableViewColumnHeader.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,24 +228,33 @@ protected override void OnApplyTemplate()
228228
_optionsButton.Tapped += OnOptionsButtonTaped;
229229
_optionsButton.DataContext = _optionsFlyoutViewModel = new OptionsFlyoutViewModel(_tableView, this);
230230

231-
var menuItem = _optionsFlyout.Items.FirstOrDefault(x => x.Name == "ItemsCheckFlyoutItem");
232-
menuItem?.ApplyTemplate();
231+
if (_optionsFlyout.Items.FirstOrDefault(x => x.Name == "ItemsCheckFlyoutItem") is { } menuItem)
232+
{
233+
menuItem.Loaded += OnItemsCheckFlyoutItemLoaded;
234+
}
235+
236+
SetFilterButtonVisibility();
237+
EnsureGridLines();
238+
}
239+
240+
/// <summary>
241+
/// Handles the Loaded event for the items check flyout item.
242+
/// </summary>
243+
private void OnItemsCheckFlyoutItemLoaded(object sender, RoutedEventArgs e)
244+
{
245+
if (sender is not MenuFlyoutItem menuItem) return;
246+
247+
menuItem.Loaded -= OnItemsCheckFlyoutItemLoaded;
233248

234249
if (menuItem?.FindDescendant<CheckBox>(x => x.Name == "SelectAllCheckBox") is { } checkBox)
235250
{
236251
_selectAllCheckBox = checkBox;
237252
_selectAllCheckBox.Content = TableViewLocalizedStrings.SelectAllParenthesized;
238253
_selectAllCheckBox.Checked += OnSelectAllCheckBoxChecked;
239254
_selectAllCheckBox.Unchecked += OnSelectAllCheckBoxUnchecked;
255+
_optionsFlyoutViewModel.SetSelectAllCheckBoxState();
240256
}
241257

242-
#if !WINDOWS
243-
if (menuItem?.FindDescendant<ListView>(x => x.Name is "FilterItemsList") is { } filterItemsList)
244-
{
245-
filterItemsList.Margin = new Thickness(12, 0, 0, 0);
246-
}
247-
#endif
248-
249258
if (menuItem?.FindDescendant<TextBox>(x => x.Name == "SearchBox") is { } searchBox)
250259
{
251260
_searchBox = searchBox;
@@ -259,9 +268,6 @@ protected override void OnApplyTemplate()
259268
// Handle Space key to prevent MenuFlyoutItem performing click action.
260269
menuItem.PreviewKeyUp += static (_, e) => e.Handled = e.Key is VirtualKey.Space;
261270
}
262-
263-
SetFilterButtonVisibility();
264-
EnsureGridLines();
265271
}
266272

267273
/// <summary>

src/Themes/TableViewColumnHeader.xaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
34
xmlns:local="using:WinUI.TableView"
45
xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5-
xmlns:not_win="http://uno.ui/not_win">
6-
6+
xmlns:not_win="http://uno.ui/not_win"
7+
mc:Ignorable="not_win">
8+
79
<ResourceDictionary.MergedDictionaries>
810
<ResourceDictionary Source="ms-appx:///WinUI.TableView/Themes/Resources.xaml" />
911
</ResourceDictionary.MergedDictionaries>
@@ -167,6 +169,7 @@
167169
<ListView x:Name="FilterItemsList"
168170
Grid.Row="2"
169171
SelectionMode="None"
172+
not_win:Margin="12,0,0,0"
170173
ItemsSource="{Binding FilterItems}">
171174
<ListView.ItemContainerStyle>
172175
<Style TargetType="ListViewItem"

0 commit comments

Comments
 (0)