Skip to content

Commit e1a2555

Browse files
committed
Added TabShapePath property to TabShape to allow styling of tab shape from XAML, and updated demo project.
1 parent 9d46b52 commit e1a2555

File tree

3 files changed

+27
-53
lines changed

3 files changed

+27
-53
lines changed

ChromeTabs/TabShape.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ public TabShape()
1212
Stretch = Stretch.Fill;
1313
}
1414

15+
public Path TabShapePath
16+
{
17+
get { return (Path)GetValue(TabShapePathProperty); }
18+
set { SetValue(TabShapePathProperty, value); }
19+
}
20+
21+
// Using a DependencyProperty as the backing store for TabShapePath. This enables animation, styling, binding, etc...
22+
public static readonly DependencyProperty TabShapePathProperty =
23+
DependencyProperty.Register("TabShapePath", typeof(Path), typeof(TabShape), new PropertyMetadata(null));
24+
25+
26+
1527
protected override Size MeasureOverride(Size constraint)
1628
{
1729
if (constraint.Width == double.PositiveInfinity || constraint.Height == double.PositiveInfinity)
@@ -25,6 +37,10 @@ protected override Size MeasureOverride(Size constraint)
2537

2638
private Geometry GetGeometry()
2739
{
40+
if(TabShapePath!= null)
41+
{
42+
return TabShapePath.Data;
43+
}
2844
double width = DesiredSize.Width - StrokeThickness;
2945

3046
double height = 25;

Demo/CustomStyleExampleWindow.xaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@
104104
<SolidColorBrush x:Key="SelectedTabStrokeBrush">WhiteSmoke</SolidColorBrush>
105105
<SolidColorBrush x:Key="TabHighlightBrush">White</SolidColorBrush>
106106
<SolidColorBrush x:Key="SelectedTabHighlighBrush">Transparent</SolidColorBrush>
107+
<Path x:Key="CustomTabShape"
108+
Data="M0,25 C0,0 2,0 10,0 15,0 95,0 100,0 106,0 108,0 108,25"/>
107109
<sys:Double x:Key="MinTabWidthToShowCloseButton">60</sys:Double>
108110
<Style TargetType="{x:Type ct:ChromeTabItem}"
109111
x:Key="CustomTabItemStyle">
@@ -131,10 +133,12 @@
131133
CommandParameter="{Binding}" />
132134
</ContextMenu>
133135
</Grid.ContextMenu>
134-
<local:CustomTabShape x:Name="TabFill"
136+
<ct:TabShape x:Name="TabFill"
135137
Grid.ColumnSpan="5"
136138
VerticalAlignment="Top"
137-
Stretch="Fill">
139+
Stretch="Fill"
140+
TabShapePath="{StaticResource CustomTabShape}">
141+
138142
<Shape.Fill>
139143
<LinearGradientBrush EndPoint="0.5,1"
140144
StartPoint="0.5,0"
@@ -147,19 +151,21 @@
147151
Offset="1" />
148152
</LinearGradientBrush>
149153
</Shape.Fill>
150-
</local:CustomTabShape>
154+
</ct:TabShape>
151155

152-
<local:CustomTabShape x:Name="TabPath"
156+
<ct:TabShape x:Name="TabPath"
153157
Grid.ColumnSpan="5"
154158
VerticalAlignment="Top"
155159
Stretch="Fill"
160+
TabShapePath="{StaticResource CustomTabShape}"
156161
Stroke="{StaticResource TabStrokeBrush}" />
157162

158-
<local:CustomTabShape x:Name="TabHighlight"
163+
<ct:TabShape x:Name="TabHighlight"
159164
Margin="1"
160165
Grid.ColumnSpan="5"
161166
VerticalAlignment="Top"
162167
Stretch="Fill"
168+
TabShapePath="{StaticResource CustomTabShape}"
163169
Stroke="{StaticResource TabHighlightBrush}" />
164170
<ContentPresenter x:Name="ContentSite"
165171
Grid.Column="1"

Demo/CustomTabShape.cs

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)