From 55579e1e3a85b50ea824da44caf04e0a9eed13ac Mon Sep 17 00:00:00 2001 From: Corvin Date: Tue, 17 Jun 2025 18:05:09 +0200 Subject: [PATCH] added AP to be able to swap between a scrollable and a wrapping header panel in a TabControl --- src/MainDemo.Wpf/Domain/TabsViewModel.cs | 6 +- src/MainDemo.Wpf/Tabs.xaml | 82 +++++++++++++++++++ src/MaterialDesignThemes.Wpf/TabAssist.cs | 18 +++- .../MaterialDesignTheme.TabControl.xaml | 82 ++++++++++++------- 4 files changed, 157 insertions(+), 31 deletions(-) diff --git a/src/MainDemo.Wpf/Domain/TabsViewModel.cs b/src/MainDemo.Wpf/Domain/TabsViewModel.cs index 08c32cc99b..26b1ad234a 100644 --- a/src/MainDemo.Wpf/Domain/TabsViewModel.cs +++ b/src/MainDemo.Wpf/Domain/TabsViewModel.cs @@ -4,10 +4,10 @@ namespace MaterialDesignDemo.Domain; -internal class TabsViewModel : ViewModelBase +internal partial class TabsViewModel : ObservableObject { public ObservableCollection CustomTabs { get; } - + public List LongList { get; } public CustomTab? SelectedTab { get; set; } public string? VeryLongText { get; set; } = @" @@ -47,6 +47,8 @@ public TabsViewModel() CustomContent = "Custom content 3", }, }; + + LongList = Enumerable.Range(1, 20).ToList(); } } diff --git a/src/MainDemo.Wpf/Tabs.xaml b/src/MainDemo.Wpf/Tabs.xaml index 60252e2997..b575c717ae 100644 --- a/src/MainDemo.Wpf/Tabs.xaml +++ b/src/MainDemo.Wpf/Tabs.xaml @@ -755,5 +755,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/MaterialDesignThemes.Wpf/TabAssist.cs b/src/MaterialDesignThemes.Wpf/TabAssist.cs index 2dd368738f..9e6abf2fc2 100644 --- a/src/MaterialDesignThemes.Wpf/TabAssist.cs +++ b/src/MaterialDesignThemes.Wpf/TabAssist.cs @@ -1,5 +1,11 @@ namespace MaterialDesignThemes.Wpf; +public enum TabControlHeaderBehavior +{ + Scrolling, + Wrapping +} + public static class TabAssist { public static readonly DependencyProperty HasFilledTabProperty = DependencyProperty.RegisterAttached( @@ -27,7 +33,7 @@ public static void SetHeaderPanelMargin(DependencyObject element, Thickness valu => element.SetValue(HeaderPanelMarginProperty, value); public static Thickness GetHeaderPanelMargin(DependencyObject element) - => (Thickness) element.GetValue(HeaderPanelMarginProperty); + => (Thickness)element.GetValue(HeaderPanelMarginProperty); internal static Visibility GetBindableIsItemsHost(DependencyObject obj) => (Visibility)obj.GetValue(BindableIsItemsHostProperty); @@ -45,4 +51,14 @@ private static void OnBindableIsItemsHostChanged(DependencyObject d, DependencyP panel.IsItemsHost = (Visibility)e.NewValue == Visibility.Visible; } } + + public static TabControlHeaderBehavior GetHeaderBehavior(DependencyObject obj) + => (TabControlHeaderBehavior)obj.GetValue(HeaderBehaviorProperty); + + public static void SetHeaderBehavior(DependencyObject obj, TabControlHeaderBehavior value) + => obj.SetValue(HeaderBehaviorProperty, value); + + public static readonly DependencyProperty HeaderBehaviorProperty = + DependencyProperty.RegisterAttached("HeaderBehavior", typeof(TabControlHeaderBehavior), typeof(TabAssist), + new PropertyMetadata(TabControlHeaderBehavior.Scrolling)); } diff --git a/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TabControl.xaml b/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TabControl.xaml index 87867f8aee..e801accd81 100644 --- a/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TabControl.xaml +++ b/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TabControl.xaml @@ -31,57 +31,83 @@ - + + + - - + - - - + + + + + + + + + Padding="{TemplateBinding Padding}" + HorizontalAlignment="Stretch" + VerticalAlignment="Stretch" + Panel.ZIndex="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Panel.ZIndex)}" + Background="{x:Null}" + Focusable="False"> + Margin="{TemplateBinding Padding}" + ContentSource="SelectedContent" + ContentStringFormat="{TemplateBinding SelectedContentStringFormat}" + ContentTemplate="{TemplateBinding SelectedContentTemplate}" + ContentTemplateSelector="{TemplateBinding SelectedContentTemplateSelector}" + Focusable="False" + SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> + + + + + + + + + +