Skip to content

Commit

Permalink
Fix issue (#116
Browse files Browse the repository at this point in the history
Fix issue (#116
  • Loading branch information
yanjinhuagood committed Dec 1, 2024
1 parent 29e96ba commit 3feb946
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -779,46 +779,90 @@
<TabItem Padding="10" Header="TabItem1">
<Rectangle Fill="{DynamicResource WD.DangerSolidColorBrush}" />
</TabItem>
<TabItem Padding="10" Header="TabItem2">
<TabItem
Padding="10"
wd:ElementHelper.IsClear="True"
Header="TabItem2">
<Rectangle Fill="{DynamicResource WD.InfoSolidColorBrush}" />
</TabItem>
<TabItem Padding="10" Header="TabItem3">
<TabItem
Padding="10"
wd:ElementHelper.IsClear="True"
Header="TabItem3">
<Rectangle Fill="{DynamicResource WD.WarningSolidColorBrush}" />
</TabItem>
</TabControl>
<TabControl Margin="4" TabStripPlacement="Bottom">
<TabItem Padding="10" Header="TabItem1">
<TabItem
Padding="10"
wd:ElementHelper.IsClear="True"
Header="1">
<Rectangle Fill="{DynamicResource WD.InfoSolidColorBrush}" />
</TabItem>
<TabItem Padding="10" Header="TabItem2">
<TabItem
x:Name="MyTabItem"
MaxWidth="120"
Padding="10"
wd:ElementHelper.IsClear="True"
Header="TabItem2LongLongLongLongLongLongLongLong"
ToolTip="{Binding ElementName=MyTabItem, Path=Header}">
<Rectangle Fill="{DynamicResource WD.DangerSolidColorBrush}" />
</TabItem>
<TabItem Padding="10" Header="TabItem3">
<TabItem
MaxWidth="120"
Padding="10"
wd:ElementHelper.IsClear="True">
<TabItem.Header>
<TextBlock
VerticalAlignment="Center"
Text="TabItem3LongLongLongLongLongLongLongLong"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap"
ToolTip="{Binding Text, RelativeSource={RelativeSource Self}}" />
</TabItem.Header>
<Rectangle Fill="{DynamicResource WD.WarningSolidColorBrush}" />
</TabItem>
</TabControl>
<TabControl Margin="4" TabStripPlacement="Left">
<TabItem Padding="10" Header="TabItem1">
<TabItem
Padding="10"
wd:ElementHelper.IsClear="True"
Header="TabItem1">
<Rectangle Fill="{DynamicResource WD.WarningSolidColorBrush}" />
</TabItem>
<TabItem Padding="10" Header="TabItem2">
<TabItem
Padding="10"
wd:ElementHelper.IsClear="True"
Header="TabItem2">
<Rectangle Fill="{DynamicResource WD.InfoSolidColorBrush}" />
</TabItem>
<TabItem Padding="10" Header="TabItem3">
<TabItem
Padding="10"
wd:ElementHelper.IsClear="True"
Header="TabItem3">
<Rectangle Fill="{DynamicResource WD.DangerSolidColorBrush}" />
</TabItem>
</TabControl>
<TabControl
Margin="4"
IsEnabled="False"
TabStripPlacement="Right">
<TabItem Padding="10" Header="TabItem1">
<TabItem
Padding="10"
wd:ElementHelper.IsClear="True"
Header="TabItem1">
<Rectangle Fill="{DynamicResource WD.SuccessSolidColorBrush}" />
</TabItem>
<TabItem Padding="10" Header="TabItem2">
<TabItem
Padding="10"
wd:ElementHelper.IsClear="True"
Header="TabItem2">
<Rectangle Fill="{DynamicResource WD.InfoSolidColorBrush}" />
</TabItem>
<TabItem Padding="10" Header="TabItem3">
<TabItem
Padding="10"
wd:ElementHelper.IsClear="True"
Header="TabItem3">
<Rectangle Fill="{DynamicResource WD.WarningSolidColorBrush}" />
</TabItem>
</TabControl>
Expand Down
9 changes: 6 additions & 3 deletions src/WPFDevelopers.Shared/Core/Helpers/ElementHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,17 @@ private static void ButtonClear_Click(object sender, RoutedEventArgs e)
if (sender is Button button)
{
if (button.TemplatedParent is TextBox textBox)
{
textBox.Clear();
}
else if (button.TemplatedParent is PasswordBox passwordBox)
{
passwordBox.Clear();
else if (button.TemplatedParent is TabItem tabItem)
{
var tabControl = tabItem.Parent as TabControl;
if (tabControl != null)
tabControl.Items.Remove(tabItem);
}
}
}

}
}
80 changes: 71 additions & 9 deletions src/WPFDevelopers.Shared/Styles/Styles.TabControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:WPFDevelopers.Controls"
xmlns:helpers="clr-namespace:WPFDevelopers.Helpers">
xmlns:helpers="clr-namespace:WPFDevelopers.Helpers"
xmlns:resx="clr-namespace:WPFDevelopers">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Themes/Basic/ControlBasic.xaml" />
<ResourceDictionary Source="../Themes/Basic/Animations.xaml" />
Expand All @@ -19,15 +20,52 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<controls:SmallPanel Background="{TemplateBinding Background}">
<controls:SmallPanel
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
Background="{TemplateBinding Background}">
<Border x:Name="PART_Border" BorderThickness="{TemplateBinding BorderThickness}" />
<ContentPresenter
x:Name="PART_ContentPresenter"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"
VerticalAlignment="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"
ContentSource="Header"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ContentPresenter
x:Name="PART_ContentPresenter"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"
VerticalAlignment="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"
ContentSource="Header"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<Button
x:Name="PART_CloseButton"
Grid.Column="1"
Width="20"
Height="20"
Margin="0,0,4,0"
helpers:ElementHelper.CornerRadius="4"
helpers:ElementHelper.IsClear="{Binding Path=(helpers:ElementHelper.IsClear), RelativeSource={RelativeSource TemplatedParent}}"
Style="{StaticResource WD.NormalButton}"
ToolTip="{Binding [Close], Source={x:Static resx:LanguageManager.Instance}}"
Visibility="Collapsed">
<controls:PathIcon
Width="10"
Height="10"
Foreground="{DynamicResource WD.SecondaryTextSolidColorBrush}"
Kind="WindowClose" />
</Button>
</Grid>
<!--<Line
x:Name="PART_Line"
Margin="{TemplateBinding Margin}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Stroke="{DynamicResource WD.SecondaryTextSolidColorBrush}"
StrokeThickness="1"
X1="2"
X2="2"
Y1="0"
Y2="15" />-->
</controls:SmallPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
Expand All @@ -38,6 +76,28 @@
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="PART_ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource WD.PrimaryNormalSolidColorBrush}" />
</Trigger>
<Trigger Property="helpers:ElementHelper.IsClear" Value="True">
<Setter TargetName="PART_CloseButton" Property="Visibility" Value="Visible" />
</Trigger>
<!--<Trigger Property="TabStripPlacement" Value="Left">
<Setter TargetName="PART_Line" Property="X1" Value="0" />
<Setter TargetName="PART_Line" Property="X2" Value="15" />
<Setter TargetName="PART_Line" Property="Y1" Value="2" />
<Setter TargetName="PART_Line" Property="Y2" Value="2" />
<Setter TargetName="PART_Line" Property="VerticalAlignment" Value="Bottom" />
<Setter TargetName="PART_Line" Property="HorizontalAlignment" Value="Center" />
</Trigger>
<Trigger Property="TabStripPlacement" Value="Right">
<Setter TargetName="PART_Line" Property="X1" Value="0" />
<Setter TargetName="PART_Line" Property="X2" Value="15" />
<Setter TargetName="PART_Line" Property="Y1" Value="2" />
<Setter TargetName="PART_Line" Property="Y2" Value="2" />
<Setter TargetName="PART_Line" Property="VerticalAlignment" Value="Bottom" />
<Setter TargetName="PART_Line" Property="HorizontalAlignment" Value="Center" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="PART_Line" Property="Visibility" Value="Collapsed" />
</Trigger>-->
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
Expand Down Expand Up @@ -85,6 +145,8 @@
<ControlTemplate TargetType="{x:Type TabControl}">
<controls:WDBorder
x:Name="PART_Border"
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
Margin="{TemplateBinding Margin}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
Expand Down

0 comments on commit 3feb946

Please sign in to comment.