Skip to content

Commit 3ac685e

Browse files
TabControl - Add opt-in AP to control margin on header (#3634)
* Add new AP to support custom margin in TabControl header * Apply new AP in TabControl template * Add sample usage of AP in demo app
1 parent 3057e93 commit 3ac685e

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

src/MainDemo.Wpf/Tabs.xaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,26 @@
365365

366366
</WrapPanel>
367367

368+
<WrapPanel>
369+
<smtx:XamlDisplay Margin="0,0,16,16"
370+
HorizontalAlignment="Left"
371+
UniqueKey="tabs_custom_7">
372+
<TabControl Width="300"
373+
materialDesign:ColorZoneAssist.Mode="SecondaryDark"
374+
Style="{StaticResource MaterialDesignFilledTabControl}"
375+
materialDesign:TabAssist.HeaderPanelMargin="20,0">
376+
<TabItem Header="TAB 1">
377+
<TextBlock Margin="8"
378+
Text="Notice left header margin" />
379+
</TabItem>
380+
<TabItem Header="TAB 2">
381+
<TextBlock Margin="8"
382+
Text="Notice right header margin" />
383+
</TabItem>
384+
</TabControl>
385+
</smtx:XamlDisplay>
386+
</WrapPanel>
387+
368388
<Rectangle Style="{StaticResource PageSectionSeparator}" />
369389

370390
<TextBlock Style="{StaticResource PageSectionTitleTextBlock}"

src/MaterialDesignThemes.Wpf/TabAssist.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,29 @@ public static class TabAssist
55
public static readonly DependencyProperty HasFilledTabProperty = DependencyProperty.RegisterAttached(
66
"HasFilledTab", typeof(bool), typeof(TabAssist), new PropertyMetadata(false));
77

8-
public static void SetHasFilledTab(DependencyObject element, bool value) => element.SetValue(HasFilledTabProperty, value);
8+
public static void SetHasFilledTab(DependencyObject element, bool value)
9+
=> element.SetValue(HasFilledTabProperty, value);
910

10-
public static bool GetHasFilledTab(DependencyObject element) => (bool)element.GetValue(HasFilledTabProperty);
11+
public static bool GetHasFilledTab(DependencyObject element)
12+
=> (bool)element.GetValue(HasFilledTabProperty);
1113

1214
public static readonly DependencyProperty HasUniformTabWidthProperty = DependencyProperty.RegisterAttached(
1315
"HasUniformTabWidth", typeof(bool), typeof(TabAssist), new PropertyMetadata(false));
1416

15-
public static void SetHasUniformTabWidth(DependencyObject element, bool value) => element.SetValue(HasUniformTabWidthProperty, value);
17+
public static void SetHasUniformTabWidth(DependencyObject element, bool value)
18+
=> element.SetValue(HasUniformTabWidthProperty, value);
1619

17-
public static bool GetHasUniformTabWidth(DependencyObject element) => (bool)element.GetValue(HasUniformTabWidthProperty);
20+
public static bool GetHasUniformTabWidth(DependencyObject element)
21+
=> (bool)element.GetValue(HasUniformTabWidthProperty);
22+
23+
public static readonly DependencyProperty HeaderPanelMarginProperty = DependencyProperty.RegisterAttached(
24+
"HeaderPanelMargin", typeof(Thickness), typeof(TabAssist), new PropertyMetadata(default(Thickness)));
25+
26+
public static void SetHeaderPanelMargin(DependencyObject element, Thickness value)
27+
=> element.SetValue(HeaderPanelMarginProperty, value);
28+
29+
public static Thickness GetHeaderPanelMargin(DependencyObject element)
30+
=> (Thickness) element.GetValue(HeaderPanelMarginProperty);
1831

1932
internal static Visibility GetBindableIsItemsHost(DependencyObject obj)
2033
=> (Visibility)obj.GetValue(BindableIsItemsHostProperty);

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TabControl.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@
4747
<StackPanel>
4848
<UniformGrid x:Name="CenteredHeaderPanel"
4949
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
50+
Margin="{Binding Path=(wpf:TabAssist.HeaderPanelMargin), RelativeSource={RelativeSource TemplatedParent}}"
5051
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
5152
wpf:TabAssist.BindableIsItemsHost="{Binding Visibility, RelativeSource={RelativeSource Self}}"
5253
Focusable="False"
5354
KeyboardNavigation.TabIndex="1"
5455
Rows="1" />
5556
<VirtualizingStackPanel x:Name="HeaderPanel"
5657
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
58+
Margin="{Binding Path=(wpf:TabAssist.HeaderPanelMargin), RelativeSource={RelativeSource TemplatedParent}}"
5759
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
5860
wpf:TabAssist.BindableIsItemsHost="{Binding Visibility, RelativeSource={RelativeSource Self}}"
5961
Focusable="False"

0 commit comments

Comments
 (0)