Skip to content

Commit 640a85e

Browse files
committed
basic template for TabControl
1 parent bc96e46 commit 640a85e

File tree

7 files changed

+154
-0
lines changed

7 files changed

+154
-0
lines changed

MainDemo.Wpf/MainDemo.Wpf.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@
114114
<Compile Include="ProvingGround.xaml.cs">
115115
<DependentUpon>ProvingGround.xaml</DependentUpon>
116116
</Compile>
117+
<Compile Include="TabControl.xaml.cs">
118+
<DependentUpon>TabControl.xaml</DependentUpon>
119+
</Compile>
117120
<Compile Include="TextFields.xaml.cs">
118121
<DependentUpon>TextFields.xaml</DependentUpon>
119122
</Compile>
@@ -184,6 +187,10 @@
184187
<SubType>Designer</SubType>
185188
<Generator>MSBuild:Compile</Generator>
186189
</Page>
190+
<Page Include="TabControl.xaml">
191+
<SubType>Designer</SubType>
192+
<Generator>MSBuild:Compile</Generator>
193+
</Page>
187194
<Page Include="TextFields.xaml">
188195
<SubType>Designer</SubType>
189196
<Generator>MSBuild:Compile</Generator>

MainDemo.Wpf/MainWindow.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@
109109
<wpfExample:Expander />
110110
</domain:DemoItem.Content>
111111
</domain:DemoItem>
112+
<domain:DemoItem Name="Tab control">
113+
<domain:DemoItem.Content>
114+
<wpfExample:TabControl />
115+
</domain:DemoItem.Content>
116+
</domain:DemoItem>
112117
<domain:DemoItem Name="Menus &amp; Tool Bars">
113118
<domain:DemoItem.Content>
114119
<wpfExample:MenusAndToolBars />

MainDemo.Wpf/TabControl.xaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<UserControl x:Class="MaterialDesignColors.WpfExample.TabControl"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:MaterialDesignColors.WpfExample"
7+
mc:Ignorable="d"
8+
d:DesignHeight="400" d:DesignWidth="600">
9+
<Grid>
10+
<TabControl Background="{DynamicResource MaterialDesignBackground}">
11+
<TabItem Header="ITEM 1">
12+
<TextBlock Text="item 1" />
13+
</TabItem>
14+
<TabItem Header="ITEM 2">
15+
<TextBlock Text="item 2" />
16+
</TabItem>
17+
<TabItem Header="ITEM 3" IsEnabled="False">
18+
<TextBlock Text="item 3" />
19+
</TabItem>
20+
</TabControl>
21+
</Grid>
22+
</UserControl>

MainDemo.Wpf/TabControl.xaml.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Navigation;
14+
using System.Windows.Shapes;
15+
16+
namespace MaterialDesignColors.WpfExample
17+
{
18+
public partial class TabControl : UserControl
19+
{
20+
public TabControl()
21+
{
22+
InitializeComponent();
23+
}
24+
}
25+
}

MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@
148148
<SubType>Designer</SubType>
149149
<Generator>MSBuild:Compile</Generator>
150150
</Page>
151+
<Page Include="Themes\MaterialDesignTheme.TabControl.xaml">
152+
<SubType>Designer</SubType>
153+
<Generator>MSBuild:Compile</Generator>
154+
</Page>
151155
<Page Include="Themes\MaterialDesignTheme.TextBox.xaml">
152156
<SubType>Designer</SubType>
153157
<Generator>MSBuild:Compile</Generator>

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Defaults.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ScrollBar.xaml" />
2525
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ScrollViewer.xaml" />
2626
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/materialdesigntheme.slider.xaml" />
27+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.TabControl.xaml" />
2728
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/materialdesigntheme.textbox.xaml" />
2829
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/materialdesigntheme.togglebutton.xaml" />
2930
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ToolBar.xaml" />
@@ -51,6 +52,8 @@
5152
<Style TargetType="{x:Type ScrollBar}" BasedOn="{StaticResource MaterialDesignScrollBar}" />
5253
<Style TargetType="{x:Type ScrollViewer}" BasedOn="{StaticResource MaterialDesignScrollViewer}" />
5354
<Style TargetType="{x:Type Slider}" BasedOn="{StaticResource MaterialDesignSlider}" />
55+
<Style TargetType="{x:Type TabControl}" BasedOn="{StaticResource MaterialDesignTabControl}" />
56+
<Style TargetType="{x:Type TabItem}" BasedOn="{StaticResource MaterialDesignTabItem}" />
5457
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource MaterialDesignTextBox}" />
5558
<Style TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource MaterialDesignSwitchToggleButton}" />
5659
<Style TargetType="{x:Type ToolBar}" BasedOn="{StaticResource MaterialDesignToolBar}" />
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf">
4+
5+
<Style x:Key="MaterialDesignTabControl" TargetType="{x:Type TabControl}">
6+
<Setter Property="BorderThickness" Value="0" />
7+
</Style>
8+
9+
<Style x:Key="MaterialDesignTabItem" TargetType="{x:Type TabItem}">
10+
<Setter Property="Background" Value="{DynamicResource MaterialDesignBackground}" />
11+
<Setter Property="Template">
12+
<Setter.Value>
13+
<ControlTemplate TargetType="{x:Type TabItem}">
14+
<ControlTemplate.Resources>
15+
<Storyboard x:Key="OnSelected">
16+
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="clickBorder" Storyboard.TargetProperty="Opacity">
17+
<DiscreteDoubleKeyFrame KeyTime="0" Value="0" />
18+
<EasingDoubleKeyFrame KeyTime="0:0:0.05" Value="1">
19+
<EasingDoubleKeyFrame.EasingFunction>
20+
<CircleEase EasingMode="EaseOut" />
21+
</EasingDoubleKeyFrame.EasingFunction>
22+
</EasingDoubleKeyFrame>
23+
<DiscreteDoubleKeyFrame KeyTime="0:0:0.6" Value="1" />
24+
<EasingDoubleKeyFrame KeyTime="0:0:0.8" Value="0">
25+
<EasingDoubleKeyFrame.EasingFunction>
26+
<SineEase EasingMode="EaseOut" />
27+
</EasingDoubleKeyFrame.EasingFunction>
28+
</EasingDoubleKeyFrame>
29+
</DoubleAnimationUsingKeyFrames>
30+
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="clickBorder">
31+
<EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="1"/>
32+
<EasingDoubleKeyFrame KeyTime="0:0:0.8" Value="1"/>
33+
<EasingDoubleKeyFrame KeyTime="0:0:0.81" Value="0"/>
34+
</DoubleAnimationUsingKeyFrames>
35+
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="border">
36+
<EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="1"/>
37+
<EasingDoubleKeyFrame KeyTime="0:0:0.8" Value="1"/>
38+
</DoubleAnimationUsingKeyFrames>
39+
</Storyboard>
40+
<Storyboard x:Key="OnDeselected">
41+
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="border">
42+
<EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="0"/>
43+
<EasingDoubleKeyFrame KeyTime="0:0:0.8" Value="0"/>
44+
</DoubleAnimationUsingKeyFrames>
45+
</Storyboard>
46+
</ControlTemplate.Resources>
47+
<Grid Background="{TemplateBinding Background}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
48+
<Border x:Name="clickBorder" Background="{DynamicResource MaterialDesignFlatButtonClick}" Opacity="0" RenderTransformOrigin="0.5,0.5">
49+
<Border.RenderTransform>
50+
<TransformGroup>
51+
<ScaleTransform ScaleX="0"/>
52+
<SkewTransform/>
53+
<RotateTransform/>
54+
<TranslateTransform/>
55+
</TransformGroup>
56+
</Border.RenderTransform>
57+
</Border>
58+
<ContentPresenter x:Name="headerContent" ContentSource="Header" HorizontalAlignment="Center" Margin="16,8,16,8" RecognizesAccessKey="True" VerticalAlignment="Center" />
59+
<Border x:Name="border" Background="{DynamicResource PrimaryHueMidBrush}" Height="2" HorizontalAlignment="Stretch" Padding="8" RenderTransformOrigin="0.5,0.5" VerticalAlignment="Bottom">
60+
<Border.RenderTransform>
61+
<TransformGroup>
62+
<ScaleTransform ScaleX="0"/>
63+
<SkewTransform/>
64+
<RotateTransform/>
65+
<TranslateTransform/>
66+
</TransformGroup>
67+
</Border.RenderTransform>
68+
</Border>
69+
</Grid>
70+
<ControlTemplate.Triggers>
71+
<Trigger Property="IsSelected" Value="True">
72+
<Trigger.EnterActions>
73+
<BeginStoryboard Storyboard="{StaticResource OnSelected}"/>
74+
</Trigger.EnterActions>
75+
<Trigger.ExitActions>
76+
<BeginStoryboard Storyboard="{StaticResource OnDeselected}"/>
77+
</Trigger.ExitActions>
78+
</Trigger>
79+
<Trigger Property="IsEnabled" Value="False">
80+
<Setter Property="Opacity" Value="0.23"/>
81+
</Trigger>
82+
</ControlTemplate.Triggers>
83+
</ControlTemplate>
84+
</Setter.Value>
85+
</Setter>
86+
</Style>
87+
88+
</ResourceDictionary>

0 commit comments

Comments
 (0)