Skip to content

Commit 2e8c7c3

Browse files
committed
tab bar
1 parent b9fabfc commit 2e8c7c3

File tree

9 files changed

+332
-2
lines changed

9 files changed

+332
-2
lines changed

NetDebug/MainWindow.xaml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,29 @@
66
xmlns:local="clr-namespace:MeowType.NetDebug"
77
mc:Ignorable="d"
88
Title="Net Debug" Height="450" Width="800" MinHeight="250" MinWidth="600" FontFamily="Consolas, Fira Code">
9-
<Grid>
9+
<WindowChrome.WindowChrome>
10+
<WindowChrome GlassFrameThickness="-1" NonClientFrameEdges="Left,Bottom,Right"/>
11+
</WindowChrome.WindowChrome>
12+
<Window.Template>
13+
<ControlTemplate TargetType="Window">
14+
<Border x:Name="RootBorder" Padding="3,35,3,3">
15+
<Grid x:Name="RootGrid" Background="{TemplateBinding Background}">
16+
<Border Background="Transparent"
17+
VerticalAlignment="Top" Height="30" Margin="0 -29 140 0">
18+
<local:TabBar></local:TabBar>
19+
</Border>
20+
<ContentPresenter />
21+
</Grid>
22+
</Border>
23+
<ControlTemplate.Triggers>
24+
<Trigger Property="WindowState" Value="Maximized">
25+
<Setter TargetName="RootGrid" Property="Margin" Value="5" />
26+
<Setter TargetName="RootBorder" Property="Padding" Value="2,30,2,2" />
27+
</Trigger>
28+
</ControlTemplate.Triggers>
29+
</ControlTemplate>
30+
</Window.Template>
31+
<Grid Background="White">
1032
<local:Udp></local:Udp>
1133
</Grid>
1234
</Window>

NetDebug/NetDebug.csproj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@
7575
<DependentUpon>MsgBox.xaml</DependentUpon>
7676
</Compile>
7777
<Compile Include="PortKind.cs" />
78+
<Compile Include="Tab.xaml.cs">
79+
<DependentUpon>Tab.xaml</DependentUpon>
80+
</Compile>
81+
<Compile Include="TabBar.xaml.cs">
82+
<DependentUpon>TabBar.xaml</DependentUpon>
83+
</Compile>
84+
<Compile Include="TabBg.xaml.cs">
85+
<DependentUpon>TabBg.xaml</DependentUpon>
86+
</Compile>
7887
<Compile Include="TargetPort.xaml.cs">
7988
<DependentUpon>TargetPort.xaml</DependentUpon>
8089
</Compile>
@@ -115,6 +124,18 @@
115124
<SubType>Designer</SubType>
116125
<Generator>MSBuild:Compile</Generator>
117126
</Page>
127+
<Page Include="Tab.xaml">
128+
<SubType>Designer</SubType>
129+
<Generator>MSBuild:Compile</Generator>
130+
</Page>
131+
<Page Include="TabBar.xaml">
132+
<SubType>Designer</SubType>
133+
<Generator>MSBuild:Compile</Generator>
134+
</Page>
135+
<Page Include="TabBg.xaml">
136+
<SubType>Designer</SubType>
137+
<Generator>MSBuild:Compile</Generator>
138+
</Page>
118139
<Page Include="TargetPort.xaml">
119140
<SubType>Designer</SubType>
120141
<Generator>MSBuild:Compile</Generator>

NetDebug/Tab.xaml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<UserControl x:Class="MeowType.NetDebug.Tab"
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:MeowType.NetDebug"
7+
mc:Ignorable="d" Name="_this"
8+
d:DesignHeight="30" d:DesignWidth="200" MinWidth="50" MaxWidth="200">
9+
<UserControl.Resources>
10+
<Style x:Key="FocusVisual">
11+
<Setter Property="Control.Template">
12+
<Setter.Value>
13+
<ControlTemplate>
14+
<Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
15+
</ControlTemplate>
16+
</Setter.Value>
17+
</Setter>
18+
</Style>
19+
<SolidColorBrush x:Key="Button.Static.Background" Color="#00DDDDDD"/>
20+
<SolidColorBrush x:Key="Button.MouseOver.Background" Color="#AADDDDDD"/>
21+
<SolidColorBrush x:Key="Button.Pressed.Background" Color="#CCDDDDDD"/>
22+
<SolidColorBrush x:Key="Button.Disabled.Background" Color="#FFF4F4F4"/>
23+
<SolidColorBrush x:Key="Button.Disabled.Foreground" Color="#FF838383"/>
24+
<Style x:Key="CloseButtonStyle" TargetType="{x:Type Button}">
25+
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
26+
<Setter Property="Background" Value="{StaticResource Button.Static.Background}"/>
27+
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
28+
<Setter Property="BorderThickness" Value="1"/>
29+
<Setter Property="HorizontalContentAlignment" Value="Center"/>
30+
<Setter Property="VerticalContentAlignment" Value="Center"/>
31+
<Setter Property="Padding" Value="1"/>
32+
<Setter Property="Template">
33+
<Setter.Value>
34+
<ControlTemplate TargetType="{x:Type Button}">
35+
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
36+
<ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
37+
</Border>
38+
<ControlTemplate.Triggers>
39+
<Trigger Property="IsDefaulted" Value="true">
40+
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
41+
</Trigger>
42+
<Trigger Property="IsMouseOver" Value="true">
43+
<Setter Property="Background" TargetName="border" Value="{StaticResource Button.MouseOver.Background}"/>
44+
</Trigger>
45+
<Trigger Property="IsPressed" Value="true">
46+
<Setter Property="Background" TargetName="border" Value="{StaticResource Button.Pressed.Background}"/>
47+
</Trigger>
48+
<Trigger Property="IsEnabled" Value="false">
49+
<Setter Property="Background" TargetName="border" Value="{StaticResource Button.Disabled.Background}"/>
50+
<Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{StaticResource Button.Disabled.Foreground}"/>
51+
</Trigger>
52+
</ControlTemplate.Triggers>
53+
</ControlTemplate>
54+
</Setter.Value>
55+
</Setter>
56+
</Style>
57+
</UserControl.Resources>
58+
<Grid>
59+
<local:TabBg></local:TabBg>
60+
61+
<Grid WindowChrome.IsHitTestVisibleInChrome="True">
62+
<Grid.ColumnDefinitions>
63+
<ColumnDefinition Width="*"></ColumnDefinition>
64+
<ColumnDefinition Width="15"></ColumnDefinition>
65+
</Grid.ColumnDefinitions>
66+
<Label Name="TabContent" DataContext="{Binding ElementName=_this}" Content="{Binding Title, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Foreground="#FF454545" Padding="5,0" Margin="5,0,15,0" VerticalAlignment="Center"/>
67+
<Button Grid.Column="1" Height="15" Width="15" BorderThickness="0" Padding="0" Margin="-15,0,0,0" Click="Close_Click" Style="{DynamicResource CloseButtonStyle}">
68+
<Button.OpacityMask>
69+
<VisualBrush>
70+
<VisualBrush.Visual>
71+
<Ellipse Fill="White" Width="15" Height="15" />
72+
</VisualBrush.Visual>
73+
</VisualBrush>
74+
</Button.OpacityMask>
75+
<Button.Content>
76+
<Grid ClipToBounds="True">
77+
<Label FontSize="10" Padding="0" Margin="0" RenderTransformOrigin="0.5,0.5" Foreground="#FF787878">
78+
<Label.RenderTransform>
79+
<TransformGroup>
80+
<ScaleTransform ScaleX="1.5" ScaleY="1.5"/>
81+
<SkewTransform/>
82+
<RotateTransform/>
83+
<TranslateTransform/>
84+
</TransformGroup>
85+
</Label.RenderTransform> ×
86+
</Label>
87+
</Grid>
88+
</Button.Content>
89+
</Button>
90+
</Grid>
91+
</Grid>
92+
</UserControl>

NetDebug/Tab.xaml.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 MeowType.NetDebug
17+
{
18+
using static Utils;
19+
/// <summary>
20+
/// Tab.xaml 的交互逻辑
21+
/// </summary>
22+
public partial class Tab : UserControl
23+
{
24+
public Tab()
25+
{
26+
InitializeComponent();
27+
}
28+
29+
public delegate void OnCloseClick(object sender, RoutedEventArgs e);
30+
public event OnCloseClick OnClose;
31+
32+
33+
public string Title
34+
{
35+
get => (string)GetValue(TabTextProperty);
36+
set
37+
{
38+
SetValue(TabTextProperty, value);
39+
TabContent.Content = value;
40+
}
41+
}
42+
43+
private void Close_Click(object sender, RoutedEventArgs e)
44+
{
45+
OnClose?.Invoke(sender, e);
46+
}
47+
}
48+
}

NetDebug/TabBar.xaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<UserControl x:Class="MeowType.NetDebug.TabBar"
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:MeowType.NetDebug"
7+
mc:Ignorable="d"
8+
d:DesignHeight="30" d:DesignWidth="800">
9+
<Grid ClipToBounds="True" Margin="0,-10,0,0">
10+
<Grid Background="white" Height="1" VerticalAlignment="Bottom">
11+
<Grid.Effect>
12+
<DropShadowEffect ShadowDepth="0" BlurRadius="5" Opacity="0.3"/>
13+
</Grid.Effect>
14+
<Grid.OpacityMask>
15+
<LinearGradientBrush>
16+
<GradientStop Color="white" Offset="0.9" />
17+
<GradientStop Color="Transparent" Offset="1.0" />
18+
</LinearGradientBrush>
19+
</Grid.OpacityMask>
20+
</Grid>
21+
22+
<StackPanel Orientation="Horizontal" Margin="10,10,10,0">
23+
<StackPanel.Effect>
24+
<DropShadowEffect ShadowDepth="0" BlurRadius="10" Opacity="0.2"/>
25+
</StackPanel.Effect>
26+
<local:Tab Title="Udp"></local:Tab>
27+
</StackPanel>
28+
</Grid>
29+
30+
</UserControl>

NetDebug/TabBar.xaml.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 MeowType.NetDebug
17+
{
18+
/// <summary>
19+
/// TabBar.xaml 的交互逻辑
20+
/// </summary>
21+
public partial class TabBar : UserControl
22+
{
23+
public TabBar()
24+
{
25+
InitializeComponent();
26+
}
27+
}
28+
}

NetDebug/TabBg.xaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<UserControl x:Class="MeowType.NetDebug.TabBg"
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:MeowType.NetDebug"
7+
mc:Ignorable="d"
8+
d:DesignHeight="30" d:DesignWidth="250">
9+
<Grid ClipToBounds="True" Margin="-10,0,-10,0">
10+
<Grid.ColumnDefinitions>
11+
<ColumnDefinition Width="10"></ColumnDefinition>
12+
<ColumnDefinition Width="*"></ColumnDefinition>
13+
<ColumnDefinition Width="10"></ColumnDefinition>
14+
</Grid.ColumnDefinitions>
15+
16+
<Border Grid.Column="0" Background="White" Width="15" Height="15" VerticalAlignment="Bottom" Margin="-5,0,0,-0.5" RenderTransformOrigin="0.5,0.5">
17+
<Border.RenderTransform>
18+
<TransformGroup>
19+
<ScaleTransform/>
20+
<SkewTransform/>
21+
<RotateTransform/>
22+
<TranslateTransform X="1"/>
23+
</TransformGroup>
24+
</Border.RenderTransform>
25+
<Border.OpacityMask>
26+
<VisualBrush Stretch="None">
27+
<VisualBrush.Visual>
28+
<Path Fill="White" StrokeThickness="0" Data="M0,15 C15,15 15,0 15,0 L15,15 z"/>
29+
</VisualBrush.Visual>
30+
</VisualBrush>
31+
</Border.OpacityMask>
32+
</Border>
33+
<Border Grid.Column="2" Background="White" Width="15" Height="15" VerticalAlignment="Bottom" Margin="-0.5,0,0,-0.5">
34+
<Border.RenderTransform>
35+
<TransformGroup>
36+
<ScaleTransform/>
37+
<SkewTransform/>
38+
<RotateTransform/>
39+
<TranslateTransform X="-1"/>
40+
</TransformGroup>
41+
</Border.RenderTransform>
42+
<Border.OpacityMask>
43+
<VisualBrush Stretch="None">
44+
<VisualBrush.Visual>
45+
<Path Fill="White" StrokeThickness="0" Data="M0,15 C15,15 15,0 15,0 L15,15 z" RenderTransformOrigin="0.5,0.5">
46+
<Path.RenderTransform>
47+
<TransformGroup>
48+
<ScaleTransform ScaleY="1" ScaleX="-1"/>
49+
<SkewTransform AngleY="0" AngleX="0"/>
50+
<RotateTransform Angle="0"/>
51+
<TranslateTransform/>
52+
</TransformGroup>
53+
</Path.RenderTransform>
54+
</Path>
55+
</VisualBrush.Visual>
56+
</VisualBrush>
57+
</Border.OpacityMask>
58+
</Border>
59+
<Border Grid.Column="1" Background="White" CornerRadius="10,10,0,0"></Border>
60+
</Grid>
61+
</UserControl>

NetDebug/TabBg.xaml.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 MeowType.NetDebug
17+
{
18+
/// <summary>
19+
/// TabBg.xaml 的交互逻辑
20+
/// </summary>
21+
public partial class TabBg : UserControl
22+
{
23+
public TabBg()
24+
{
25+
InitializeComponent();
26+
}
27+
}
28+
}

NetDebug/Utils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace MeowType.NetDebug
1212
internal static class Utils
1313
{
1414
public readonly static DependencyProperty DefaultPortProperty = DependencyProperty.Register("DefaultPort", typeof(string), typeof(PortKind), new PropertyMetadata("12345"));
15-
public readonly static DependencyProperty OnSendProperty = DependencyProperty.Register("OnSendDelegate", typeof(Action<object, RoutedEventArgs>), typeof(MsgBox));
15+
public readonly static DependencyProperty TabTextProperty = DependencyProperty.Register("Title", typeof(string), typeof(Tab), new PropertyMetadata("NoTitle"));
1616

1717
public readonly static FontFamily FiraCodeLight = new FontFamily(new Uri("pack://application:,,,/"), "./#Fira Code Light");
1818

0 commit comments

Comments
 (0)