Skip to content

Commit 1a307de

Browse files
authored
added AP to be able to swap between a scrollable and a wrapping header panel in a TabControl (#3952)
1 parent b19d824 commit 1a307de

File tree

4 files changed

+294
-131
lines changed

4 files changed

+294
-131
lines changed

src/MainDemo.Wpf/Domain/TabsViewModel.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace MaterialDesignDemo.Domain;
66

7-
internal class TabsViewModel : ViewModelBase
7+
internal partial class TabsViewModel : ObservableObject
88
{
99
public ObservableCollection<CustomTab> CustomTabs { get; }
10-
10+
public List<int> LongList { get; }
1111
public CustomTab? SelectedTab { get; set; }
1212

1313
public string? VeryLongText { get; set; } = @"
@@ -47,6 +47,8 @@ public TabsViewModel()
4747
CustomContent = "Custom content 3",
4848
},
4949
};
50+
51+
LongList = Enumerable.Range(1, 20).ToList();
5052
}
5153

5254
}

src/MainDemo.Wpf/Tabs.xaml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,5 +755,87 @@
755755
</materialDesign:Card>
756756
</smtx:XamlDisplay>
757757

758+
<Border Width="720"
759+
BorderBrush="{DynamicResource MaterialDesign.Brush.Primary}"
760+
BorderThickness="1">
761+
<Grid>
762+
<Grid.RowDefinitions>
763+
<RowDefinition Height="auto" />
764+
<RowDefinition Height="*" />
765+
</Grid.RowDefinitions>
766+
<Grid.ColumnDefinitions>
767+
<ColumnDefinition Width="*" MinWidth="50" />
768+
<ColumnDefinition Width="2" />
769+
<ColumnDefinition Width="*" MinWidth="50" />
770+
</Grid.ColumnDefinitions>
771+
772+
<materialDesign:ColorZone Grid.ColumnSpan="2"
773+
Padding="8"
774+
Mode="PrimaryMid">
775+
<TextBlock Text="materialDesign:TabAssist.HeaderBehavior=&quot;Scrolling&quot;" />
776+
</materialDesign:ColorZone>
777+
778+
<materialDesign:ColorZone Grid.Column="2"
779+
Padding="8"
780+
Mode="PrimaryMid">
781+
<TextBlock Text="materialDesign:TabAssist.HeaderBehavior=&quot;Wrapping&quot;" />
782+
</materialDesign:ColorZone>
783+
784+
<smtx:XamlDisplay Grid.Row="1"
785+
Grid.Column="0"
786+
Margin="16"
787+
UniqueKey="tabs_tabAssist_1">
788+
<TabControl materialDesign:TabAssist.HeaderBehavior="Scrolling"
789+
ItemsSource="{Binding LongList}"
790+
Style="{StaticResource MaterialDesignTabControl}">
791+
<TabControl.ItemTemplate>
792+
<DataTemplate>
793+
<StackPanel Orientation="Horizontal">
794+
<TextBlock Text="{Binding ., StringFormat=Header {0}}" />
795+
</StackPanel>
796+
</DataTemplate>
797+
</TabControl.ItemTemplate>
798+
<TabControl.ContentTemplate>
799+
<DataTemplate>
800+
<TextBlock Margin="10"
801+
FontSize="18"
802+
Text="{Binding ., StringFormat=Content {0}}" />
803+
</DataTemplate>
804+
</TabControl.ContentTemplate>
805+
</TabControl>
806+
</smtx:XamlDisplay>
807+
808+
<GridSplitter Grid.RowSpan="2"
809+
Grid.Column="1"
810+
HorizontalAlignment="Stretch"
811+
VerticalAlignment="Stretch" />
812+
813+
<smtx:XamlDisplay Grid.Row="1"
814+
Grid.Column="2"
815+
Margin="16"
816+
UniqueKey="tabs_tabAssist_2">
817+
<TabControl materialDesign:TabAssist.HeaderBehavior="Wrapping"
818+
ItemsSource="{Binding LongList}"
819+
Style="{StaticResource MaterialDesignTabControl}">
820+
<TabControl.ItemTemplate>
821+
<DataTemplate>
822+
<StackPanel Orientation="Horizontal">
823+
<TextBlock Text="{Binding ., StringFormat=Header {0}}" />
824+
</StackPanel>
825+
</DataTemplate>
826+
</TabControl.ItemTemplate>
827+
<TabControl.ContentTemplate>
828+
<DataTemplate>
829+
<TextBlock Margin="10"
830+
FontSize="18"
831+
Text="{Binding ., StringFormat=Content {0}}" />
832+
</DataTemplate>
833+
</TabControl.ContentTemplate>
834+
</TabControl>
835+
</smtx:XamlDisplay>
836+
837+
</Grid>
838+
</Border>
839+
758840
</StackPanel>
759841
</UserControl>

src/MaterialDesignThemes.Wpf/TabAssist.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
namespace MaterialDesignThemes.Wpf;
22

3+
public enum TabControlHeaderBehavior
4+
{
5+
Scrolling,
6+
Wrapping
7+
}
38
public static class TabAssist
49
{
510
public static readonly DependencyProperty HasFilledTabProperty = DependencyProperty.RegisterAttached(
@@ -54,4 +59,14 @@ public static void SetTabHeaderCursor(DependencyObject obj, Cursor value)
5459

5560
public static readonly DependencyProperty TabHeaderCursorProperty =
5661
DependencyProperty.RegisterAttached("TabHeaderCursor", typeof(Cursor), typeof(TabAssist), new PropertyMetadata(Cursors.Hand));
62+
63+
public static TabControlHeaderBehavior GetHeaderBehavior(DependencyObject obj)
64+
=> (TabControlHeaderBehavior)obj.GetValue(HeaderBehaviorProperty);
65+
66+
public static void SetHeaderBehavior(DependencyObject obj, TabControlHeaderBehavior value)
67+
=> obj.SetValue(HeaderBehaviorProperty, value);
68+
69+
public static readonly DependencyProperty HeaderBehaviorProperty =
70+
DependencyProperty.RegisterAttached("HeaderBehavior", typeof(TabControlHeaderBehavior), typeof(TabAssist),
71+
new PropertyMetadata(TabControlHeaderBehavior.Scrolling));
5772
}

0 commit comments

Comments
 (0)