Skip to content

Commit 73b1ebc

Browse files
committed
add: hex三种模式
1 parent 10b2732 commit 73b1ebc

File tree

3 files changed

+83
-37
lines changed

3 files changed

+83
-37
lines changed

llcomNext/LLCOM/Controls/PacketDataControl.axaml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@
1616
Hex="44 55 66 77 88 99 00 AA BB CC DD EE FF"
1717
MainColor="{DynamicResource SemiGreen8}"
1818
Text="接收到的xxx数据123123接" />
19+
<controls:PacketDataControl
20+
Extra="2025/03/11 - 11:22:33.123"
21+
Header="本机 &lt;&lt; 串口1"
22+
Hex="44 55 66 77 88 99 00 AA BB CC DD EE FF"
23+
MainColor="{DynamicResource SemiGreen8}"
24+
ShowHex="False"
25+
ShowString="False"
26+
Text="接收到的xxx数据123123接" />
27+
<controls:PacketDataControl
28+
Extra="2025/03/11 - 11:22:33.123"
29+
Header="本机 &lt;&lt; 串口1"
30+
Hex="44 55 66 77 88 99 00 AA BB CC DD EE FF"
31+
MainColor="{DynamicResource SemiGreen8}"
32+
ShowHex="False"
33+
Text="接收到的xxx数据123123接" />
1934
</StackPanel>
2035
</Design.PreviewWith>
2136

@@ -47,19 +62,26 @@
4762
BorderBrush="{TemplateBinding MainColor}"
4863
BorderThickness="1"
4964
CornerRadius="0 5 5 5">
50-
<StackPanel>
65+
<StackPanel Margin="5" Spacing="2">
5166
<SelectableTextBlock
52-
Margin="5,5,5,0"
5367
Background="Transparent"
5468
FontSize="16"
5569
Foreground="{TemplateBinding MainColor}"
70+
IsVisible="{Binding ShowString, RelativeSource={RelativeSource TemplatedParent}}"
5671
Text="{TemplateBinding Text}"
5772
TextWrapping="Wrap" />
5873
<SelectableTextBlock
59-
Margin="5,0,5,3"
6074
Background="Transparent"
61-
FontSize="12"
75+
FontSize="16"
76+
Foreground="{TemplateBinding MainColor}"
77+
IsVisible="{Binding !ShowString, RelativeSource={RelativeSource TemplatedParent}}"
78+
Text="{TemplateBinding Hex}"
79+
TextWrapping="Wrap" />
80+
<SelectableTextBlock
81+
Background="Transparent"
82+
FontSize="10"
6283
Foreground="{DynamicResource SemiColorText2}"
84+
IsVisible="{TemplateBinding ShowHex}"
6385
Text="{TemplateBinding Hex}"
6486
TextWrapping="Wrap" />
6587
</StackPanel>

llcomNext/LLCOM/Controls/PacketDataControl.axaml.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Avalonia;
1+
using System;
2+
using Avalonia;
23
using Avalonia.Controls;
34
using Avalonia.Controls.Primitives;
45
using Avalonia.Media;
@@ -48,4 +49,20 @@ public string? Hex
4849
get => GetValue(HexProperty);
4950
set => SetValue(HexProperty, value);
5051
}
52+
53+
public static readonly StyledProperty<bool?> ShowStringProperty =
54+
AvaloniaProperty.Register<PacketDataControl, bool?>(nameof(ShowString), defaultValue: true);
55+
public bool? ShowString
56+
{
57+
get => GetValue(ShowStringProperty);
58+
set => SetValue(ShowStringProperty, value);
59+
}
60+
61+
public static readonly StyledProperty<bool?> ShowHexProperty =
62+
AvaloniaProperty.Register<PacketDataControl, bool?>(nameof(ShowHex), defaultValue: true);
63+
public bool? ShowHex
64+
{
65+
get => GetValue(ShowHexProperty);
66+
set => SetValue(ShowHexProperty, value);
67+
}
5168
}

llcomNext/LLCOM/Views/DataViews/PacketDataView.axaml

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,6 @@
1414
<Design.DataContext>
1515
<vm:PacketDataViewModel />
1616
</Design.DataContext>
17-
<!-- <ScrollViewer Margin="5,5,10,5"> -->
18-
<!-- <StackPanel Spacing="5"> -->
19-
<!-- <PacketDataControl -->
20-
<!-- Extra="2025/03/11 - 11:22:33.123" -->
21-
<!-- Header="本机 &lt;&lt; 串口1" -->
22-
<!-- Hex="11 22 33 44 55 66 77 88 99 00 AA BB CC DD EE FF11 22 33 44 55 66 77 88 99 00 AA BB CC DD EE FF11 22 33 44 55 66 77 88 99 00 AA BB CC DD EE FF11 22 33 44 55 66 77 88 99 00 AA BB CC DD EE FF" -->
23-
<!-- MainColor="{DynamicResource SemiGreen8}" -->
24-
<!-- Text="接收到的xxx数据123123接收到的xxx数据123123接收到的xxx数据123123接收到的xxx数据123123接收到的xxx数据123123接收到的xxx数据123123接收到的xxx数据123123接收到的xxx数据123123" /> -->
25-
<!-- <PacketDataControl -->
26-
<!-- Extra="2025/03/11 - 11:22:33.123" -->
27-
<!-- Header="串口1 &gt;&gt; 本机" -->
28-
<!-- Hex="11 22 33 44 55 66 77 88 99 00 AA BB CC DD EE FF11 22 33 44 55 66 77 88 99 00 AA BB CC DD EE FF11 22 33 44 55 66 77 88 99 00 AA BB CC DD EE FF11 22 33 44 55 66 77 88 99 00 AA BB CC DD EE FF" -->
29-
<!-- MainColor="{DynamicResource SemiRed8}" -->
30-
<!-- Text="接收到的xxx数据123123接收到的xxx数据123123接收到的xxx数据123123接收到的xxx数据123123接收到的xxx数据123123接收到的xxx数据123123接收到的xxx数据123123接收到的xxx数据123123" /> -->
31-
<!-- </StackPanel> -->
32-
<!-- </ScrollViewer> -->
3317
<UserControl.Styles>
3418
<Style Selector="ListBoxItem">
3519
<Setter Property="Padding" Value="0 0 0 5" />
@@ -41,20 +25,43 @@
4125
<Setter Property="Background" Value="Transparent" />
4226
</Style>
4327
</UserControl.Styles>
44-
<ListBox
45-
Margin="5,5,10,5"
46-
u:ScrollTo.ButtonTheme="{DynamicResource PrimaryScrollToButton}"
47-
u:ScrollTo.Direction="Bottom"
48-
ItemsSource="{Binding PacketData}">
49-
<ListBox.ItemTemplate>
50-
<DataTemplate>
51-
<controls:PacketDataControl
52-
Extra="{Binding Extra}"
53-
Header="{Binding TagString}"
54-
Hex="{Binding HexString}"
55-
MainColor="{DynamicResource SemiGreen8}"
56-
Text="{Binding String}" />
57-
</DataTemplate>
58-
</ListBox.ItemTemplate>
59-
</ListBox>
28+
<Grid RowDefinitions="auto *">
29+
<ListBox
30+
Grid.Row="1"
31+
Margin="0,5"
32+
u:ScrollTo.ButtonTheme="{DynamicResource PrimaryScrollToButton}"
33+
u:ScrollTo.Direction="Bottom"
34+
ItemsSource="{Binding PacketData}">
35+
<ListBox.ItemTemplate>
36+
<DataTemplate>
37+
<controls:PacketDataControl
38+
Margin="5,0,10,0"
39+
Extra="{Binding Extra}"
40+
Header="{Binding TagString}"
41+
Hex="{Binding HexString}"
42+
MainColor="{DynamicResource SemiGreen8}"
43+
Text="{Binding String}" />
44+
</DataTemplate>
45+
</ListBox.ItemTemplate>
46+
</ListBox>
47+
<Border
48+
Grid.Row="0"
49+
Background="{DynamicResource SemiColorBackground2}"
50+
BorderBrush="{DynamicResource SemiColorBorder}"
51+
BorderThickness="0,0,0,1">
52+
<StackPanel
53+
Margin="5"
54+
HorizontalAlignment="Right"
55+
Orientation="Horizontal"
56+
Spacing="5">
57+
<CheckBox VerticalAlignment="Center" Content="转义不可见字符" />
58+
<CheckBox
59+
VerticalAlignment="Center"
60+
Content="Hex模式"
61+
IsThreeState="True" />
62+
<CheckBox VerticalAlignment="Center" Content="自动滚动" />
63+
<Button Content="清空数据" />
64+
</StackPanel>
65+
</Border>
66+
</Grid>
6067
</UserControl>

0 commit comments

Comments
 (0)