Skip to content

Commit 176304e

Browse files
committed
add: 颜色绑定
1 parent 73b1ebc commit 176304e

File tree

6 files changed

+65
-39
lines changed

6 files changed

+65
-39
lines changed

llcomNext/LLCOM/Controls/PacketDataControl.axaml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,29 @@
66
<StackPanel Width="500">
77
<controls:PacketDataControl
88
Extra="2025/03/11 - 11:22:33.123"
9-
Header="本机 &lt;&lt; 串口1"
9+
Header="串口1"
1010
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"
11+
Icon="&#xE02E;"
1112
MainColor="{DynamicResource SemiGreen8}"
1213
Text="接收到的xxx数据123123接收到的xxx数据123123接收到的xxx数据123123接收到的xxx数据123123接收到的xxx数据123123接收到的xxx数据123123接收到的xxx数据123123接收到的xxx数据123123" />
1314
<controls:PacketDataControl
1415
Extra="2025/03/11 - 11:22:33.123"
15-
Header="本机 &lt;&lt; 串口1"
16+
Header="串口1"
1617
Hex="44 55 66 77 88 99 00 AA BB CC DD EE FF"
17-
MainColor="{DynamicResource SemiGreen8}"
18+
Icon="&#xE05A;"
19+
MainColor="{DynamicResource SemiRed8}"
1820
Text="接收到的xxx数据123123接" />
1921
<controls:PacketDataControl
2022
Extra="2025/03/11 - 11:22:33.123"
21-
Header="本机 &lt;&lt; 串口1"
23+
Header="串口1"
2224
Hex="44 55 66 77 88 99 00 AA BB CC DD EE FF"
2325
MainColor="{DynamicResource SemiGreen8}"
2426
ShowHex="False"
2527
ShowString="False"
2628
Text="接收到的xxx数据123123接" />
2729
<controls:PacketDataControl
2830
Extra="2025/03/11 - 11:22:33.123"
29-
Header="本机 &lt;&lt; 串口1"
31+
Header="串口1"
3032
Hex="44 55 66 77 88 99 00 AA BB CC DD EE FF"
3133
MainColor="{DynamicResource SemiGreen8}"
3234
ShowHex="False"
@@ -45,11 +47,21 @@
4547
BorderBrush="{TemplateBinding MainColor}"
4648
BorderThickness="1,1,1,0"
4749
CornerRadius="5 5 0 0">
48-
<TextBlock
50+
<StackPanel
4951
Margin="6,2"
50-
FontSize="12"
51-
Foreground="{DynamicResource SemiColorHighlight}"
52-
Text="{TemplateBinding Header}" />
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>
5365
</Border>
5466
<SelectableTextBlock
5567
Margin="0,2,10,0"

llcomNext/LLCOM/Controls/PacketDataControl.axaml.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ public IBrush? MainColor
1717
set => SetValue(MainColorProperty, value);
1818
}
1919

20+
public static readonly StyledProperty<string?> IconProperty =
21+
AvaloniaProperty.Register<PacketDataControl, string?>(nameof(Icon));
22+
public string? Icon
23+
{
24+
get => GetValue(IconProperty);
25+
set => SetValue(IconProperty, value);
26+
}
27+
2028
public static readonly StyledProperty<string?> HeaderProperty =
2129
AvaloniaProperty.Register<PacketDataControl, string?>(nameof(Header));
2230
public string? Header

llcomNext/LLCOM/Models/PacketData.cs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,22 @@ public PacketData(byte[] data, MessageWay way, string channel, string? extra = n
4040
/// <summary>
4141
/// 该包的字符串表示
4242
/// </summary>
43-
public string String { get; set; } = string.Empty;
43+
public string String { get; set; }
4444

4545
/// <summary>
4646
/// 数据包的方向
4747
/// </summary>
48-
public MessageWay Way { get; set; } = MessageWay.Unknown;
48+
public MessageWay Way { get; set; }
4949

5050
/// <summary>
5151
/// 消息通道类型
5252
/// </summary>
53-
public string Channel { get; set; } = string.Empty;
54-
55-
/// <summary>
56-
/// 表示该包的方向和通道的字符串
57-
/// </summary>
58-
public string TagString
59-
{
60-
get
61-
{
62-
return Way switch
63-
{
64-
MessageWay.Unknown => $"{Channel}",
65-
MessageWay.Send => $"本机 >> {Channel}",//TODO 多语言支持
66-
MessageWay.Receive => $"{Channel} >> 本机",//TODO 多语言支持
67-
_ => throw new ArgumentOutOfRangeException()
68-
};
69-
}
70-
}
53+
public string Channel { get; set; }
54+
55+
public bool IsWayUnknown => Way == MessageWay.Unknown;
56+
public bool IsWaySend => Way == MessageWay.Send;
57+
public bool IsWayReceive => Way == MessageWay.Receive;
58+
7159

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

llcomNext/LLCOM/Services/Utils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
namespace LLCOM.Services;
1111

12-
public class Utils
12+
public static class Utils
1313
{
14-
private static string? _version = "1.0.0.0";//null;
14+
private static string? _version = null;
1515
/// <summary>
1616
/// 软件版本
1717
/// </summary>

llcomNext/LLCOM/ViewModels/DataViews/PacketDataViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public PacketDataViewModel(Func<Type, ViewModelBase> getService)
2323
private ObservableCollection<PacketData> _packetData = [
2424
new PacketData([0x30, 0x31, 0x32, 0x33], MessageWay.Send, "串口1"),
2525
new PacketData([0x30, 0x31, 0x32, 0x33], MessageWay.Receive, "串口1"),
26-
new PacketData([0x30, 0x31, 0x32, 0x33], MessageWay.Send, "串口1"),
26+
new PacketData([0x30, 0x31, 0x32, 0x33], MessageWay.Unknown, "串口1"),
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: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
x:Class="LLCOM.Views.PacketDataView"
33
xmlns="https://github.com/avaloniaui"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5-
xmlns:controls="clr-namespace:LLCOM.Controls"
65
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
76
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
87
xmlns:u="https://irihi.tech/ursa"
@@ -15,15 +14,29 @@
1514
<vm:PacketDataViewModel />
1615
</Design.DataContext>
1716
<UserControl.Styles>
17+
<!-- 防止ListBoxItem被选中时背景色变化 -->
1818
<Style Selector="ListBoxItem">
19-
<Setter Property="Padding" Value="0 0 0 5" />
19+
<Setter Property="Padding" Value="0 0 0 3" />
2020
</Style>
2121
<Style Selector="ListBoxItem:pointerover">
2222
<Setter Property="Background" Value="Transparent" />
2323
</Style>
2424
<Style Selector="ListBoxItem:selected">
2525
<Setter Property="Background" Value="Transparent" />
2626
</Style>
27+
<!-- 几种颜色的样式 -->
28+
<Style Selector="PacketDataControl.Green">
29+
<Setter Property="MainColor" Value="{DynamicResource SemiGreen8}" />
30+
<Setter Property="Icon" Value="&#xE12A;" />
31+
</Style>
32+
<Style Selector="PacketDataControl.Red">
33+
<Setter Property="MainColor" Value="{DynamicResource SemiRed8}" />
34+
<Setter Property="Icon" Value="&#xE128;" />
35+
</Style>
36+
<Style Selector="PacketDataControl.Black">
37+
<Setter Property="MainColor" Value="{DynamicResource SemiGrey8}" />
38+
<Setter Property="Icon" Value="&#xEAE8;" />
39+
</Style>
2740
</UserControl.Styles>
2841
<Grid RowDefinitions="auto *">
2942
<ListBox
@@ -34,12 +47,14 @@
3447
ItemsSource="{Binding PacketData}">
3548
<ListBox.ItemTemplate>
3649
<DataTemplate>
37-
<controls:PacketDataControl
50+
<PacketDataControl
3851
Margin="5,0,10,0"
52+
Classes.Black="{Binding IsWayUnknown}"
53+
Classes.Green="{Binding IsWaySend}"
54+
Classes.Red="{Binding IsWayReceive}"
3955
Extra="{Binding Extra}"
40-
Header="{Binding TagString}"
56+
Header="{Binding Channel}"
4157
Hex="{Binding HexString}"
42-
MainColor="{DynamicResource SemiGreen8}"
4358
Text="{Binding String}" />
4459
</DataTemplate>
4560
</ListBox.ItemTemplate>
@@ -53,8 +68,11 @@
5368
Margin="5"
5469
HorizontalAlignment="Right"
5570
Orientation="Horizontal"
56-
Spacing="5">
57-
<CheckBox VerticalAlignment="Center" Content="转义不可见字符" />
71+
Spacing="8">
72+
<CheckBox
73+
VerticalAlignment="Center"
74+
Content="转义不可见字符"
75+
ToolTip.Tip="仅在UTF-8编码时生效" />
5876
<CheckBox
5977
VerticalAlignment="Center"
6078
Content="Hex模式"

0 commit comments

Comments
 (0)