feat: add icon in log checker
This commit is contained in:
@ -159,6 +159,7 @@ namespace HFUTCourseSimulation.Dialog {
|
||||
|
||||
var courseNameLabel = new TextBlock();
|
||||
courseNameLabel.Text = lesson.name;
|
||||
courseNameLabel.TextWrapping = TextWrapping.Wrap;
|
||||
courseNameLabel.Foreground = new SolidColorBrush(lesson.color.Foreground);
|
||||
courseNameLabel.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
courseNameLabel.VerticalAlignment = VerticalAlignment.Center;
|
||||
|
@ -94,6 +94,7 @@
|
||||
<Compile Include="Util\ColorConsistency.cs" />
|
||||
<Compile Include="Util\ColorPair.cs" />
|
||||
<Compile Include="Util\ColorTrans.cs" />
|
||||
<Compile Include="Util\WpfValueConv.cs" />
|
||||
<Compile Include="Util\WeekNames.cs" />
|
||||
<Compile Include="Util\Win32Dialog.cs" />
|
||||
<Compile Include="Widget\ColorPicker.xaml.cs">
|
||||
|
@ -15,7 +15,7 @@ namespace HFUTCourseSimulation.Util {
|
||||
/// <summary>
|
||||
/// UI界面的背景色(白天或夜晚(然而没有实现,现在全是白天模式))
|
||||
/// </summary>
|
||||
public static ColorPair Backboard = new ColorPair(Colors.Black, Colors.White);
|
||||
public static ColorPair Backboard => new ColorPair(Colors.Black, Colors.White);
|
||||
//public static ColorPair Backboard = new ColorPair(Colors.White, Colors.Black);
|
||||
|
||||
/// <summary>
|
||||
@ -48,6 +48,11 @@ namespace HFUTCourseSimulation.Util {
|
||||
/// </summary>
|
||||
public static Color ChessboardColor => Color.FromArgb(20, 127, 127, 127);
|
||||
|
||||
|
||||
public static ColorPair InfoColor => new ColorPair(Colors.Black, Colors.White);
|
||||
public static ColorPair WarningColor => ColorPreset.MdColors.Amber;
|
||||
public static ColorPair ErrorColor => ColorPreset.MdColors.Red;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
98
HFUTCourseSimulation/Util/WpfValueConv.cs
Normal file
98
HFUTCourseSimulation/Util/WpfValueConv.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace HFUTCourseSimulation.Util.WpfValueConv {
|
||||
|
||||
[ValueConversion(typeof(bool), typeof(Visibility))]
|
||||
public class EnableToVisibility : IValueConverter {
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
var v = (bool)value;
|
||||
return v ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
[ValueConversion(typeof(Kernel.ReporterKind), typeof(Color))]
|
||||
public class MsgKindToForegroundColor : IValueConverter {
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
var v = (Kernel.ReporterKind)value;
|
||||
switch (v) {
|
||||
case Kernel.ReporterKind.Info:
|
||||
return ColorConsistency.InfoColor.Foreground;
|
||||
case Kernel.ReporterKind.Warning:
|
||||
return ColorConsistency.WarningColor.Foreground;
|
||||
case Kernel.ReporterKind.Error:
|
||||
return ColorConsistency.ErrorColor.Foreground;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
[ValueConversion(typeof(Kernel.ReporterKind), typeof(Color))]
|
||||
public class MsgKindToBackgroundColor : IValueConverter {
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
var v = (Kernel.ReporterKind)value;
|
||||
switch (v) {
|
||||
case Kernel.ReporterKind.Info:
|
||||
return ColorConsistency.InfoColor.Background;
|
||||
case Kernel.ReporterKind.Warning:
|
||||
return ColorConsistency.WarningColor.Background;
|
||||
case Kernel.ReporterKind.Error:
|
||||
return ColorConsistency.ErrorColor.Background;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
[ValueConversion(typeof(Kernel.ReporterKind), typeof(BitmapSource))]
|
||||
public class MsgKindToIcon : IValueConverter {
|
||||
private static BitmapSource CreateWpfSystemIcon(System.Drawing.Icon icon) {
|
||||
return Imaging.CreateBitmapSourceFromHIcon(
|
||||
icon.Handle, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
|
||||
}
|
||||
private static readonly BitmapSource InfoIcon = CreateWpfSystemIcon(System.Drawing.SystemIcons.Information);
|
||||
private static readonly BitmapSource WarningIcon = CreateWpfSystemIcon(System.Drawing.SystemIcons.Warning);
|
||||
private static readonly BitmapSource ErrorIcon = CreateWpfSystemIcon(System.Drawing.SystemIcons.Error);
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
var v = (Kernel.ReporterKind)value;
|
||||
switch (v) {
|
||||
case Kernel.ReporterKind.Info:
|
||||
return InfoIcon;
|
||||
case Kernel.ReporterKind.Warning:
|
||||
return WarningIcon;
|
||||
case Kernel.ReporterKind.Error:
|
||||
return ErrorIcon;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -5,9 +5,14 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:HFUTCourseSimulation.Widget"
|
||||
xmlns:uidata="clr-namespace:HFUTCourseSimulation.Kernel"
|
||||
xmlns:converter="clr-namespace:HFUTCourseSimulation.Util.WpfValueConv"
|
||||
mc:Ignorable="d"
|
||||
x:Name="uiMainWindow"
|
||||
Title="检查器日志" Height="500" Width="400" WindowStyle="ToolWindow" Closed="uiMainWindow_Closed" Loaded="uiMainWindow_Loaded">
|
||||
<Window.Resources>
|
||||
<converter:MsgKindToIcon x:Key="convMsgKindToIcon"/>
|
||||
</Window.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto"/>
|
||||
@ -26,7 +31,12 @@
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid d:DataContext="{d:DesignInstance uidata:ReporterEntry}">
|
||||
<TextBlock Text="{Binding Message, Mode=OneTime}"/>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image Source="{Binding Kind, Mode=OneTime, Converter={StaticResource convMsgKindToIcon}}" Grid.Column="0" VerticalAlignment="Center" Height="16" Width="16" Margin="5"/>
|
||||
<TextBlock Text="{Binding Message, Mode=OneTime}" Grid.Column="1" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
|
Reference in New Issue
Block a user