| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <UserControl x:Class="TeamAAS.Logging.Controls.LogView"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:hc="https://handyorg.github.io/handycontrol"
- xmlns:local="clr-namespace:TeamAAS.Logging.Controls" Background="{DynamicResource RegionBrush}">
- <UserControl.Resources>
- <ResourceDictionary>
- <!-- 不在此控件内合并 HC 皮肤/主题字典:本地合并的 SkinDefault(浅色)会遮蔽 App 级明暗调色板,
- 导致 RegionBrush/PrimaryTextBrush/SecondaryTextBrush/BorderBrush 等恒为浅色、无法跟随主题(明/暗)切换。
- 运行时这些画刷、GroupBoxTab.Small 及隐式 ListBoxItem 样式均由 App.xaml 合并的 HC 主题提供,可正常随主题变化。 -->
- <local:LogLevelBrushConverter x:Key="LevelBrush"/>
- <!-- 级别色(与 LogLevelBrushConverter 一致),用于筛选胶囊选中态填充 -->
- <SolidColorBrush x:Key="ChipInfoBrush" Color="#2D6CDF"/>
- <SolidColorBrush x:Key="ChipWarningBrush" Color="#FF9800"/>
- <SolidColorBrush x:Key="ChipErrorBrush" Color="#F44336"/>
- <!-- 级别筛选胶囊:未选=灰描边+次要文字,悬停=级别色描边,选中=级别色填充+白字 -->
- <Style x:Key="LevelChip" TargetType="ToggleButton">
- <Setter Property="Cursor" Value="Hand"/>
- <Setter Property="FontSize" Value="12"/>
- <Setter Property="Padding" Value="14,4"/>
- <Setter Property="Margin" Value="0,0,8,0"/>
- <Setter Property="Foreground" Value="{DynamicResource SecondaryTextBrush}"/>
- <Setter Property="Background" Value="Transparent"/>
- <Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="ToggleButton">
- <Border x:Name="Bd" CornerRadius="13" SnapsToDevicePixels="True"
- Background="{TemplateBinding Background}"
- BorderBrush="{TemplateBinding BorderBrush}"
- BorderThickness="1"
- Padding="{TemplateBinding Padding}">
- <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
- </Border>
- <ControlTemplate.Triggers>
- <Trigger Property="IsMouseOver" Value="True">
- <Setter TargetName="Bd" Property="BorderBrush" Value="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}"/>
- </Trigger>
- <Trigger Property="IsChecked" Value="True">
- <Setter TargetName="Bd" Property="Background" Value="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}"/>
- <Setter TargetName="Bd" Property="BorderBrush" Value="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}"/>
- <Setter Property="Foreground" Value="White"/>
- </Trigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
- </ResourceDictionary>
- </UserControl.Resources>
- <GroupBox Header="日志" FontSize="14" Style="{StaticResource GroupBoxTab.Small}" Background="{DynamicResource RegionBrush}">
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto"/>
- <RowDefinition Height="*"/>
- </Grid.RowDefinitions>
- <!-- 工具栏:左=级别筛选胶囊,右=清空 -->
- <Grid Grid.Row="0" Margin="2,0,0,10">
- <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
- <ToggleButton x:Name="TgInfo" Content="Info" Tag="{StaticResource ChipInfoBrush}"
- Style="{StaticResource LevelChip}" IsChecked="True"
- Checked="CategoryToggle_Changed" Unchecked="CategoryToggle_Changed"/>
- <ToggleButton x:Name="TgWarning" Content="Warning" Tag="{StaticResource ChipWarningBrush}"
- Style="{StaticResource LevelChip}" IsChecked="True"
- Checked="CategoryToggle_Changed" Unchecked="CategoryToggle_Changed"/>
- <ToggleButton x:Name="TgError" Content="Error" Tag="{StaticResource ChipErrorBrush}"
- Style="{StaticResource LevelChip}" IsChecked="True"
- Checked="CategoryToggle_Changed" Unchecked="CategoryToggle_Changed"/>
- </StackPanel>
- <Button x:Name="BtnClear" Content="清空" HorizontalAlignment="Right" VerticalAlignment="Center"
- Padding="14,4" FontSize="12" Click="BtnClear_Click"/>
- </Grid>
- <!-- 日志列表(双击一条弹出详情) -->
- <ListBox Grid.Row="1" x:Name="LogList" BorderThickness="0" Background="Transparent"
- HorizontalContentAlignment="Stretch"
- ScrollViewer.HorizontalScrollBarVisibility="Disabled"
- ScrollViewer.VerticalScrollBarVisibility="Auto"
- MouseDoubleClick="LogList_MouseDoubleClick">
- <ListBox.ItemContainerStyle>
- <!-- BasedOn HC 隐式 ListBoxItem 样式,保留悬停/选中反馈,只叠加内边距 -->
- <Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
- <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
- <Setter Property="Padding" Value="4,3"/>
- </Style>
- </ListBox.ItemContainerStyle>
- <ListBox.ItemTemplate>
- <DataTemplate>
- <Grid Margin="0,1">
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="Auto"/>
- <ColumnDefinition Width="Auto"/>
- <ColumnDefinition Width="*"/>
- </Grid.ColumnDefinitions>
- <!-- 级别徽标:小圆角色块 + 白字,固定最小宽保证时间列对齐 -->
- <Border Grid.Column="0" MinWidth="62" CornerRadius="3" Padding="6,1" Margin="0,0,8,0"
- VerticalAlignment="Top" HorizontalAlignment="Left"
- Background="{Binding Category, Converter={StaticResource LevelBrush}}">
- <TextBlock Text="{Binding CategoryText}" FontSize="10.5" FontWeight="SemiBold"
- Foreground="White" HorizontalAlignment="Center"/>
- </Border>
- <TextBlock Grid.Column="1" Text="{Binding TimeText}" FontSize="12" FontFamily="Consolas"
- Foreground="{DynamicResource SecondaryTextBrush}" VerticalAlignment="Top" Margin="0,0,10,0"/>
- <TextBlock Grid.Column="2" Text="{Binding Message}" FontSize="12" TextWrapping="Wrap"
- Foreground="{DynamicResource PrimaryTextBrush}" VerticalAlignment="Top"/>
- </Grid>
- </DataTemplate>
- </ListBox.ItemTemplate>
- </ListBox>
- </Grid>
- </GroupBox>
- </UserControl>
|