Skip to content

Commit f188712

Browse files
committed
add: 可折叠报数据标签
1 parent 7fb5002 commit f188712

File tree

6 files changed

+93
-36
lines changed

6 files changed

+93
-36
lines changed

llcomNext/LLCOM/Controls/PacketDataControl.axaml

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:controls="using:LLCOM.Controls">
55
<Design.PreviewWith>
6-
<StackPanel Width="500">
6+
<StackPanel Width="500" Height="400">
77
<controls:PacketDataControl
88
Extra="2025/03/11 - 11:22:33.123"
99
Header="串口1"
@@ -39,41 +39,11 @@
3939
<Style Selector="controls|PacketDataControl">
4040
<Setter Property="Template">
4141
<ControlTemplate>
42-
<StackPanel>
43-
<Grid>
44-
<Border
45-
HorizontalAlignment="Left"
46-
Background="{TemplateBinding MainColor}"
47-
BorderBrush="{TemplateBinding MainColor}"
48-
BorderThickness="1,1,1,0"
49-
CornerRadius="5 5 0 0">
50-
<StackPanel
51-
Margin="6,2"
52-
Orientation="Horizontal"
53-
Spacing="4">
54-
<TextBlock
55-
VerticalAlignment="Center"
56-
FontFamily="{DynamicResource Phosphor}"
57-
FontSize="12"
58-
Foreground="{DynamicResource SemiColorHighlight}"
59-
Text="{TemplateBinding Icon}" />
60-
<TextBlock
61-
FontSize="12"
62-
Foreground="{DynamicResource SemiColorHighlight}"
63-
Text="{TemplateBinding Header}" />
64-
</StackPanel>
65-
</Border>
66-
<SelectableTextBlock
67-
Margin="0,2,10,0"
68-
HorizontalAlignment="Right"
69-
FontSize="12"
70-
FontWeight="Bold"
71-
Text="{TemplateBinding Extra}" />
72-
</Grid>
42+
<StackPanel Background="Transparent">
7343
<Border
7444
BorderBrush="{TemplateBinding MainColor}"
7545
BorderThickness="1"
76-
CornerRadius="0 5 5 5">
46+
CornerRadius="{TemplateBinding DataBorderCornerRadius}">
7747
<StackPanel Margin="5" Spacing="2">
7848
<SelectableTextBlock
7949
Background="Transparent"
@@ -98,6 +68,42 @@
9868
TextWrapping="Wrap" />
9969
</StackPanel>
10070
</Border>
71+
<Grid Height="{TemplateBinding HeaderHeight}">
72+
<Grid.Transitions>
73+
<Transitions>
74+
<DoubleTransition Property="Height" Duration="0:0:0.05" />
75+
</Transitions>
76+
</Grid.Transitions>
77+
<Border
78+
HorizontalAlignment="Left"
79+
Background="{TemplateBinding MainColor}"
80+
BorderBrush="{TemplateBinding MainColor}"
81+
CornerRadius="0 0 5 5">
82+
<StackPanel
83+
Margin="6,2"
84+
Orientation="Horizontal"
85+
Spacing="4">
86+
<TextBlock
87+
VerticalAlignment="Center"
88+
FontFamily="{DynamicResource Phosphor}"
89+
FontSize="12"
90+
Foreground="{DynamicResource SemiColorHighlight}"
91+
Text="{TemplateBinding Icon}" />
92+
<TextBlock
93+
VerticalAlignment="Center"
94+
FontSize="12"
95+
Foreground="{DynamicResource SemiColorHighlight}"
96+
Text="{TemplateBinding Header}" />
97+
</StackPanel>
98+
</Border>
99+
<SelectableTextBlock
100+
Margin="0,0,10,0"
101+
HorizontalAlignment="Right"
102+
VerticalAlignment="Center"
103+
FontSize="12"
104+
FontWeight="Bold"
105+
Text="{TemplateBinding Extra}" />
106+
</Grid>
101107
</StackPanel>
102108
</ControlTemplate>
103109
</Setter>

llcomNext/LLCOM/Controls/PacketDataControl.axaml.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,31 @@ public bool? ShowHex
7373
get => GetValue(ShowHexProperty);
7474
set => SetValue(ShowHexProperty, value);
7575
}
76+
77+
78+
//用于样式的,不提供给用户
79+
80+
//响应时为0,不显示标题栏
81+
public static readonly StyledProperty<int?> HeaderHeightProperty =
82+
AvaloniaProperty.Register<PacketDataControl, int?>(nameof(HeaderHeight), defaultValue: 22);
83+
public int? HeaderHeight
84+
{
85+
get => GetValue(HeaderHeightProperty);
86+
set => SetValue(HeaderHeightProperty, value);
87+
}
88+
89+
//响应时为5 5 5 5,四角圆角
90+
public static readonly StyledProperty<CornerRadius?> DataBorderCornerRadiusProperty =
91+
AvaloniaProperty.Register<PacketDataControl, CornerRadius?>(nameof(DataBorderCornerRadius),
92+
defaultValue: new CornerRadius(5,5,5,0));
93+
public CornerRadius? DataBorderCornerRadius
94+
{
95+
get => GetValue(DataBorderCornerRadiusProperty);
96+
set => SetValue(DataBorderCornerRadiusProperty, value);
97+
}
98+
99+
public PacketDataControl()
100+
{
101+
102+
}
76103
}

llcomNext/LLCOM/Models/PacketData.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public PacketData(byte[] data, MessageWay way, string channel, string? extra = n
5656
public bool IsWaySend => Way == MessageWay.Send;
5757
public bool IsWayReceive => Way == MessageWay.Receive;
5858

59+
/// <summary>
60+
/// 是否显示hex(hex数组为空时就不显示)
61+
/// </summary>
62+
public bool IsHexVisible => Data.Length != 0;
5963

6064
/// <summary>
6165
/// 根据Data生成一个十六进制字符串

llcomNext/LLCOM/Styles/MainStyle.axaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,4 @@
3434
<Setter Property="Foreground" Value="{DynamicResource SemiColorSecondary}" />
3535
</Style>
3636

37-
3837
</Styles>

llcomNext/LLCOM/ViewModels/DataViews/PacketDataViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public PacketDataViewModel(Func<Type, ViewModelBase> getService)
2121

2222
[ObservableProperty]
2323
private ObservableCollection<PacketData> _packetData = [
24+
new PacketData([], MessageWay.Unknown, "MQTT1",null,null,true,"已连接"),
2425
new PacketData([0x30, 0x31, 0x32, 0x33], MessageWay.Send, "串口1"),
2526
new PacketData([0x30, 0x31, 0x32, 0x33], MessageWay.Receive, "串口1"),
26-
new PacketData("已连接"u8.ToArray(), MessageWay.Unknown, "MQTT1"),
2727
new PacketData([0x30, 0x31, 0x32, 0x33], MessageWay.Receive, "串口1"),
2828
new PacketData([0x30, 0x31, 0x32, 0x33], MessageWay.Send, "串口1"),
2929
new PacketData([0x30, 0x31, 0x32, 0x33], MessageWay.Receive, "串口1"),

llcomNext/LLCOM/Views/DataViews/PacketDataView.axaml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@
3737
<Setter Property="MainColor" Value="{DynamicResource SemiGrey8}" />
3838
<Setter Property="Icon" Value="&#xEAE8;" />
3939
</Style>
40+
<!-- 折叠数据包标签 -->
41+
<Style Selector="PacketDataControl.HideHeader">
42+
<Setter Property="HeaderHeight" Value="0" />
43+
<Setter Property="DataBorderCornerRadius" Value="5 5 5 5" />
44+
</Style>
45+
<Style Selector="PacketDataControl.HideHeader:pointerover">
46+
<Setter Property="HeaderHeight" Value="22" />
47+
<Setter Property="DataBorderCornerRadius" Value="5 5 5 0" />
48+
</Style>
4049
</UserControl.Styles>
4150
<Grid RowDefinitions="auto *">
4251
<ListBox
@@ -51,10 +60,12 @@
5160
Margin="5,0,10,0"
5261
Classes.Black="{Binding IsWayUnknown}"
5362
Classes.Green="{Binding IsWaySend}"
63+
Classes.HideHeader="{Binding ElementName=ShowHeaderCheckBox, Path=!IsChecked}"
5464
Classes.Red="{Binding IsWayReceive}"
5565
Extra="{Binding Extra}"
5666
Header="{Binding Channel}"
5767
Hex="{Binding HexString}"
68+
ShowHex="{Binding IsHexVisible}"
5869
Text="{Binding String}" />
5970
</DataTemplate>
6071
</ListBox.ItemTemplate>
@@ -69,15 +80,25 @@
6980
HorizontalAlignment="Right"
7081
Orientation="Horizontal"
7182
Spacing="8">
83+
<CheckBox
84+
Name="ShowHeaderCheckBox"
85+
VerticalAlignment="Center"
86+
Content="显示数据包标签"
87+
IsChecked="True" />
7288
<CheckBox
7389
VerticalAlignment="Center"
7490
Content="转义不可见字符"
91+
IsChecked="True"
7592
ToolTip.Tip="仅在UTF-8编码时生效" />
7693
<CheckBox
7794
VerticalAlignment="Center"
7895
Content="Hex模式"
96+
IsChecked="{x:Null}"
7997
IsThreeState="True" />
80-
<CheckBox VerticalAlignment="Center" Content="自动滚动" />
98+
<CheckBox
99+
VerticalAlignment="Center"
100+
Content="自动滚动"
101+
IsChecked="True" />
81102
<Button Content="清空数据" />
82103
</StackPanel>
83104
</Border>

0 commit comments

Comments
 (0)