LogView.xaml 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <UserControl x:Class="TeamAAS.Logging.Controls.LogView"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:hc="https://handyorg.github.io/handycontrol"
  5. xmlns:local="clr-namespace:TeamAAS.Logging.Controls" Background="{DynamicResource RegionBrush}">
  6. <UserControl.Resources>
  7. <ResourceDictionary>
  8. <!-- 不在此控件内合并 HC 皮肤/主题字典:本地合并的 SkinDefault(浅色)会遮蔽 App 级明暗调色板,
  9. 导致 RegionBrush/PrimaryTextBrush/SecondaryTextBrush/BorderBrush 等恒为浅色、无法跟随主题(明/暗)切换。
  10. 运行时这些画刷、GroupBoxTab.Small 及隐式 ListBoxItem 样式均由 App.xaml 合并的 HC 主题提供,可正常随主题变化。 -->
  11. <local:LogLevelBrushConverter x:Key="LevelBrush"/>
  12. <!-- 级别色(与 LogLevelBrushConverter 一致),用于筛选胶囊选中态填充 -->
  13. <SolidColorBrush x:Key="ChipInfoBrush" Color="#2D6CDF"/>
  14. <SolidColorBrush x:Key="ChipWarningBrush" Color="#FF9800"/>
  15. <SolidColorBrush x:Key="ChipErrorBrush" Color="#F44336"/>
  16. <!-- 级别筛选胶囊:未选=灰描边+次要文字,悬停=级别色描边,选中=级别色填充+白字 -->
  17. <Style x:Key="LevelChip" TargetType="ToggleButton">
  18. <Setter Property="Cursor" Value="Hand"/>
  19. <Setter Property="FontSize" Value="12"/>
  20. <Setter Property="Padding" Value="14,4"/>
  21. <Setter Property="Margin" Value="0,0,8,0"/>
  22. <Setter Property="Foreground" Value="{DynamicResource SecondaryTextBrush}"/>
  23. <Setter Property="Background" Value="Transparent"/>
  24. <Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
  25. <Setter Property="Template">
  26. <Setter.Value>
  27. <ControlTemplate TargetType="ToggleButton">
  28. <Border x:Name="Bd" CornerRadius="13" SnapsToDevicePixels="True"
  29. Background="{TemplateBinding Background}"
  30. BorderBrush="{TemplateBinding BorderBrush}"
  31. BorderThickness="1"
  32. Padding="{TemplateBinding Padding}">
  33. <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
  34. </Border>
  35. <ControlTemplate.Triggers>
  36. <Trigger Property="IsMouseOver" Value="True">
  37. <Setter TargetName="Bd" Property="BorderBrush" Value="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}"/>
  38. </Trigger>
  39. <Trigger Property="IsChecked" Value="True">
  40. <Setter TargetName="Bd" Property="Background" Value="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}"/>
  41. <Setter TargetName="Bd" Property="BorderBrush" Value="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}"/>
  42. <Setter Property="Foreground" Value="White"/>
  43. </Trigger>
  44. </ControlTemplate.Triggers>
  45. </ControlTemplate>
  46. </Setter.Value>
  47. </Setter>
  48. </Style>
  49. </ResourceDictionary>
  50. </UserControl.Resources>
  51. <GroupBox Header="日志" FontSize="14" Style="{StaticResource GroupBoxTab.Small}" Background="{DynamicResource RegionBrush}">
  52. <Grid>
  53. <Grid.RowDefinitions>
  54. <RowDefinition Height="Auto"/>
  55. <RowDefinition Height="*"/>
  56. </Grid.RowDefinitions>
  57. <!-- 工具栏:左=级别筛选胶囊,右=清空 -->
  58. <Grid Grid.Row="0" Margin="2,0,0,10">
  59. <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
  60. <ToggleButton x:Name="TgInfo" Content="Info" Tag="{StaticResource ChipInfoBrush}"
  61. Style="{StaticResource LevelChip}" IsChecked="True"
  62. Checked="CategoryToggle_Changed" Unchecked="CategoryToggle_Changed"/>
  63. <ToggleButton x:Name="TgWarning" Content="Warning" Tag="{StaticResource ChipWarningBrush}"
  64. Style="{StaticResource LevelChip}" IsChecked="True"
  65. Checked="CategoryToggle_Changed" Unchecked="CategoryToggle_Changed"/>
  66. <ToggleButton x:Name="TgError" Content="Error" Tag="{StaticResource ChipErrorBrush}"
  67. Style="{StaticResource LevelChip}" IsChecked="True"
  68. Checked="CategoryToggle_Changed" Unchecked="CategoryToggle_Changed"/>
  69. </StackPanel>
  70. <Button x:Name="BtnClear" Content="清空" HorizontalAlignment="Right" VerticalAlignment="Center"
  71. Padding="14,4" FontSize="12" Click="BtnClear_Click"/>
  72. </Grid>
  73. <!-- 日志列表(双击一条弹出详情) -->
  74. <ListBox Grid.Row="1" x:Name="LogList" BorderThickness="0" Background="Transparent"
  75. HorizontalContentAlignment="Stretch"
  76. ScrollViewer.HorizontalScrollBarVisibility="Disabled"
  77. ScrollViewer.VerticalScrollBarVisibility="Auto"
  78. MouseDoubleClick="LogList_MouseDoubleClick">
  79. <ListBox.ItemContainerStyle>
  80. <!-- BasedOn HC 隐式 ListBoxItem 样式,保留悬停/选中反馈,只叠加内边距 -->
  81. <Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
  82. <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
  83. <Setter Property="Padding" Value="4,3"/>
  84. </Style>
  85. </ListBox.ItemContainerStyle>
  86. <ListBox.ItemTemplate>
  87. <DataTemplate>
  88. <Grid Margin="0,1">
  89. <Grid.ColumnDefinitions>
  90. <ColumnDefinition Width="Auto"/>
  91. <ColumnDefinition Width="Auto"/>
  92. <ColumnDefinition Width="*"/>
  93. </Grid.ColumnDefinitions>
  94. <!-- 级别徽标:小圆角色块 + 白字,固定最小宽保证时间列对齐 -->
  95. <Border Grid.Column="0" MinWidth="62" CornerRadius="3" Padding="6,1" Margin="0,0,8,0"
  96. VerticalAlignment="Top" HorizontalAlignment="Left"
  97. Background="{Binding Category, Converter={StaticResource LevelBrush}}">
  98. <TextBlock Text="{Binding CategoryText}" FontSize="10.5" FontWeight="SemiBold"
  99. Foreground="White" HorizontalAlignment="Center"/>
  100. </Border>
  101. <TextBlock Grid.Column="1" Text="{Binding TimeText}" FontSize="12" FontFamily="Consolas"
  102. Foreground="{DynamicResource SecondaryTextBrush}" VerticalAlignment="Top" Margin="0,0,10,0"/>
  103. <TextBlock Grid.Column="2" Text="{Binding Message}" FontSize="12" TextWrapping="Wrap"
  104. Foreground="{DynamicResource PrimaryTextBrush}" VerticalAlignment="Top"/>
  105. </Grid>
  106. </DataTemplate>
  107. </ListBox.ItemTemplate>
  108. </ListBox>
  109. </Grid>
  110. </GroupBox>
  111. </UserControl>