diff --git a/src/Wpf.Ui.Gallery/ViewModels/Windows/MainWindowViewModel.cs b/src/Wpf.Ui.Gallery/ViewModels/Windows/MainWindowViewModel.cs index 7e96e95c5..43531e71d 100644 --- a/src/Wpf.Ui.Gallery/ViewModels/Windows/MainWindowViewModel.cs +++ b/src/Wpf.Ui.Gallery/ViewModels/Windows/MainWindowViewModel.cs @@ -72,7 +72,7 @@ public partial class MainWindowViewModel : ObservableObject { new NavigationViewItem(nameof(System.Windows.Controls.DataGrid), typeof(DataGridPage)), new NavigationViewItem(nameof(ListBox), typeof(ListBoxPage)), - new NavigationViewItem(nameof(ListView), typeof(ListViewPage)), + new NavigationViewItem(nameof(Ui.Controls.ListView), typeof(ListViewPage)), new NavigationViewItem(nameof(TreeView), typeof(TreeViewPage)), #if DEBUG new NavigationViewItem("TreeList", typeof(TreeListPage)), diff --git a/src/Wpf.Ui.Gallery/Views/Pages/Collections/ListViewPage.xaml b/src/Wpf.Ui.Gallery/Views/Pages/Collections/ListViewPage.xaml index 345d4b568..35cdf639c 100644 --- a/src/Wpf.Ui.Gallery/Views/Pages/Collections/ListViewPage.xaml +++ b/src/Wpf.Ui.Gallery/Views/Pages/Collections/ListViewPage.xaml @@ -12,7 +12,7 @@ Title="ListViewPage" d:DataContext="{d:DesignInstance local:ListViewPage, IsDesignTimeCreatable=False}" - d:DesignHeight="450" + d:DesignHeight="750" d:DesignWidth="800" ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}" ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}" @@ -30,17 +30,18 @@ \t</ListView.ItemTemplate>\n </ListView> - - + - - + + @@ -58,13 +59,14 @@ - - + @@ -98,8 +100,8 @@ Text="{Binding Company, Mode=OneWay}" /> - - + + + + + + <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\t<GridViewColumn DisplayMemberBinding="{Binding LastName}" Header="Last Name"/>\n + \t\t\t<GridViewColumn DisplayMemberBinding="{Binding Company}" Header="Company"/>\n + \t\t</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 d6c8aa11a..389daa086 100644 --- a/src/Wpf.Ui/Controls/AutoSuggestBox/AutoSuggestBox.xaml +++ b/src/Wpf.Ui/Controls/AutoSuggestBox/AutoSuggestBox.xaml @@ -144,7 +144,7 @@ BorderThickness="1" CornerRadius="8" SnapsToDevicePixels="True"> - - + - - + + diff --git a/src/Wpf.Ui/Controls/ListView/ListView.cs b/src/Wpf.Ui/Controls/ListView/ListView.cs new file mode 100644 index 000000000..8520cd916 --- /dev/null +++ b/src/Wpf.Ui/Controls/ListView/ListView.cs @@ -0,0 +1,88 @@ +namespace Wpf.Ui.Controls; + +/// +/// Extends , and adds customized support or . +/// +/// +/// +/// <ui:ListView ItemsSource="{Binding ...}" > +/// <ui:ListView.View> +/// <GridView> +/// <GridViewColumn +/// DisplayMemberBinding="{Binding FirstName}" +/// Header="First Name" /> +/// <GridViewColumn +/// DisplayMemberBinding="{Binding LastName}" +/// Header="Last Name" /> +/// </GridView> +/// </ui:ListView.View> +/// </ui:ListView> +/// +/// +public class ListView : System.Windows.Controls.ListView +{ + /// Identifies the dependency property. + public static readonly DependencyProperty ViewStateProperty = DependencyProperty.Register(nameof(ViewState), typeof(ListViewViewState), typeof(ListView), new FrameworkPropertyMetadata(ListViewViewState.Default, OnViewStateChanged)); + + /// + /// Gets or sets the view state of the , enabling custom logic based on the current view. + /// + /// The current view state of the . + public ListViewViewState ViewState + { + get => (ListViewViewState)GetValue(ViewStateProperty); + set => SetValue(ViewStateProperty, value); + } + + private static void OnViewStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is not ListView self) + { + return; + } + + self.OnViewStateChanged(e); + } + + protected virtual void OnViewStateChanged(DependencyPropertyChangedEventArgs e) + { + // Hook for derived classes to react to ViewState property changes + } + + public ListView() + { + Loaded += OnLoaded; + } + + private void OnLoaded(object sender, RoutedEventArgs e) + { + Loaded -= OnLoaded; // prevent memory leaks + + // Setup initial ViewState and hook into View property changes + var descriptor = DependencyPropertyDescriptor.FromProperty(System.Windows.Controls.ListView.ViewProperty, typeof(System.Windows.Controls.ListView)); + descriptor?.AddValueChanged(this, OnViewPropertyChanged); + UpdateViewState(); // set the initial state + } + + private void OnViewPropertyChanged(object? sender, EventArgs e) + { + UpdateViewState(); + } + + private void UpdateViewState() + { + ListViewViewState viewState = View switch + { + System.Windows.Controls.GridView => ListViewViewState.GridView, + null => ListViewViewState.Default, + _ => ListViewViewState.Default + }; + + SetCurrentValue(ViewStateProperty, viewState); + } + + static ListView() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(ListView), new FrameworkPropertyMetadata(typeof(ListView))); + } +} diff --git a/src/Wpf.Ui/Controls/ListView/ListView.xaml b/src/Wpf.Ui/Controls/ListView/ListView.xaml index bef8c8cb2..1af21cff0 100644 --- a/src/Wpf.Ui/Controls/ListView/ListView.xaml +++ b/src/Wpf.Ui/Controls/ListView/ListView.xaml @@ -10,10 +10,154 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:Wpf.Ui.Controls"> - + + + + + + + + + + + + + + + - -