diff --git a/src/Wpf.Ui.Gallery/Views/Pages/Collections/ListViewPage.xaml b/src/Wpf.Ui.Gallery/Views/Pages/Collections/ListViewPage.xaml index 35cdf639c..e03078edc 100644 --- a/src/Wpf.Ui.Gallery/Views/Pages/Collections/ListViewPage.xaml +++ b/src/Wpf.Ui.Gallery/Views/Pages/Collections/ListViewPage.xaml @@ -121,31 +121,34 @@ <ListView ItemsSource="{Binding ViewModel.BasicListViewItems}">\n \t<ListView.View>\n - \t\t<GridView>\n - \t\t\t<GridViewColumn DisplayMemberBinding="{Binding FirstName}" Header="First Name"/>\n + \t\t<ui:GridView>\n + \t\t\t<GridViewColumn DisplayMemberBinding="{Binding FirstName}" Header="First Name" MinWidth=&quot;100&quot; MaxWidth=&quot;200&quot;/>\n \t\t\t<GridViewColumn DisplayMemberBinding="{Binding LastName}" Header="Last Name"/>\n \t\t\t<GridViewColumn DisplayMemberBinding="{Binding Company}" Header="Company"/>\n - \t\t</GridView>\n + \t\t</ui:GridView>\n \t</ListView.View>\n </ListView> - - + - - - + + diff --git a/src/Wpf.Ui/Controls/AutoSuggestBox/AutoSuggestBox.xaml b/src/Wpf.Ui/Controls/AutoSuggestBox/AutoSuggestBox.xaml index 389daa086..5465b4a70 100644 --- a/src/Wpf.Ui/Controls/AutoSuggestBox/AutoSuggestBox.xaml +++ b/src/Wpf.Ui/Controls/AutoSuggestBox/AutoSuggestBox.xaml @@ -13,7 +13,7 @@ 24 14 - + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Wpf.Ui/Controls/GridView/GridViewHeaderRowIndicator.xaml b/src/Wpf.Ui/Controls/GridView/GridViewHeaderRowIndicator.xaml new file mode 100644 index 000000000..77537437e --- /dev/null +++ b/src/Wpf.Ui/Controls/GridView/GridViewHeaderRowIndicator.xaml @@ -0,0 +1,26 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/Wpf.Ui/Controls/GridView/GridViewHeaderRowPresenter.cs b/src/Wpf.Ui/Controls/GridView/GridViewHeaderRowPresenter.cs new file mode 100644 index 000000000..d16d22226 --- /dev/null +++ b/src/Wpf.Ui/Controls/GridView/GridViewHeaderRowPresenter.cs @@ -0,0 +1,84 @@ +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. +// Copyright (C) Leszek Pomianowski and WPF UI Contributors. +// All Rights Reserved. + +using System.Diagnostics; +using System.Reflection; +using System.Windows.Controls; + +namespace Wpf.Ui.Controls; + +/// +/// Extends , and adds layout support for , which can have and . +/// +public class GridViewHeaderRowPresenter : System.Windows.Controls.GridViewHeaderRowPresenter +{ + public GridViewHeaderRowPresenter() + { + Loaded += OnLoaded; + } + + protected override Size ArrangeOverride(Size arrangeSize) + { + // update the desired width of each column (clamps desiredwidth to MinWidth and MaxWidth) + if (Columns != null) + { + foreach (GridViewColumn column in Columns.OfType()) + { + column.UpdateDesiredWidth(); + } + } + + return base.ArrangeOverride(arrangeSize); + } + + protected override Size MeasureOverride(Size constraint) + { + if (Columns != null) + { + foreach (GridViewColumn column in Columns.OfType()) + { + column.UpdateDesiredWidth(); + } + } + + return base.MeasureOverride(constraint); + } + + private void OnLoaded(object sender, RoutedEventArgs e) + { + UpdateIndicatorStyle(); + } + + private void UpdateIndicatorStyle() + { + FieldInfo? indicatorField = typeof(System.Windows.Controls.GridViewHeaderRowPresenter).GetField("_indicator", BindingFlags.NonPublic | BindingFlags.Instance); + + if (indicatorField == null) + { + Debug.WriteLine("Failed to get the _indicator field"); + return; + } + + if (indicatorField.GetValue(this) is Separator indicator) + { + indicator.Margin = new Thickness(0); + indicator.Width = 3.0; + + ResourceDictionary resourceDictionary = new() + { + Source = new Uri("pack://application:,,,/Wpf.Ui;component/Controls/GridView/GridViewHeaderRowIndicator.xaml", UriKind.Absolute) + }; + + if (resourceDictionary["GridViewHeaderRowIndicatorTemplate"] is ControlTemplate template) + { + indicator.Template = template; + } + else + { + Debug.WriteLine("Failed to get the GridViewHeaderRowIndicatorTemplate"); + } + } + } +} diff --git a/src/Wpf.Ui/Controls/GridView/GridViewRowPresenter.cs b/src/Wpf.Ui/Controls/GridView/GridViewRowPresenter.cs new file mode 100644 index 000000000..0ba3e9334 --- /dev/null +++ b/src/Wpf.Ui/Controls/GridView/GridViewRowPresenter.cs @@ -0,0 +1,37 @@ +using System.Reflection; +using System.Windows.Controls; + +namespace Wpf.Ui.Controls; + +/// +/// Extends , and adds header row layout support for , which can have and . +/// +public class GridViewRowPresenter : System.Windows.Controls.GridViewRowPresenter +{ + protected override Size ArrangeOverride(Size arrangeSize) + { + // update the desired width of each column (clamps desiredwidth to MinWidth and MaxWidth) + if (Columns != null) + { + foreach (GridViewColumn column in Columns.OfType()) + { + column.UpdateDesiredWidth(); + } + } + + return base.ArrangeOverride(arrangeSize); + } + + protected override Size MeasureOverride(Size constraint) + { + if (Columns != null) + { + foreach (GridViewColumn column in Columns.OfType()) + { + column.UpdateDesiredWidth(); + } + } + + return base.MeasureOverride(constraint); + } +} diff --git a/src/Wpf.Ui/Controls/ListView/ListView.cs b/src/Wpf.Ui/Controls/ListView/ListView.cs index 4398631be..31e0237be 100644 --- a/src/Wpf.Ui/Controls/ListView/ListView.cs +++ b/src/Wpf.Ui/Controls/ListView/ListView.cs @@ -7,14 +7,14 @@ namespace Wpf.Ui.Controls; /// /// <ui:ListView ItemsSource="{Binding ...}" > /// <ui:ListView.View> -/// <GridView> +/// <ui:GridView> /// <GridViewColumn /// DisplayMemberBinding="{Binding FirstName}" /// Header="First Name" /> /// <GridViewColumn /// DisplayMemberBinding="{Binding LastName}" /// Header="Last Name" /> -/// </GridView> +/// </ui:GridView> /// </ui:ListView.View> /// </ui:ListView> /// @@ -96,4 +96,14 @@ static ListView() new FrameworkPropertyMetadata(typeof(ListView)) ); } + + protected override DependencyObject GetContainerForItemOverride() + { + return new ListViewItem(); + } + + protected override bool IsItemItsOwnContainerOverride(object item) + { + return item is ListViewItem; + } } diff --git a/src/Wpf.Ui/Controls/ListView/ListView.xaml b/src/Wpf.Ui/Controls/ListView/ListView.xaml index 1af21cff0..6e6eb9711 100644 --- a/src/Wpf.Ui/Controls/ListView/ListView.xaml +++ b/src/Wpf.Ui/Controls/ListView/ListView.xaml @@ -59,8 +59,9 @@ Focusable="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"> - + - - - - + - + - + - - -