98 lines
2.8 KiB
C#
98 lines
2.8 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using ThreadPilot.Services;
|
|
using ThreadPilot.ViewModels;
|
|
|
|
namespace ThreadPilot.Views
|
|
{
|
|
public partial class LogViewerView : System.Windows.Controls.UserControl
|
|
{
|
|
public LogViewerView()
|
|
{
|
|
this.InitializeComponent();
|
|
this.Loaded += this.OnLoaded;
|
|
}
|
|
|
|
private void OnLoaded(object sender, RoutedEventArgs e)
|
|
{
|
|
TaskSafety.FireAndForget(this.OnLoadedAsync(), _ =>
|
|
{
|
|
// Keep the view loaded even if background initialization fails.
|
|
});
|
|
}
|
|
|
|
private async Task OnLoadedAsync()
|
|
{
|
|
if (this.DataContext is LogViewerViewModel viewModel)
|
|
{
|
|
await viewModel.InitializeAsync();
|
|
}
|
|
}
|
|
}
|
|
|
|
public class BytesToMegabytesConverter : IValueConverter
|
|
{
|
|
public static readonly BytesToMegabytesConverter Instance = new();
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value is long bytes)
|
|
{
|
|
return bytes / (1024.0 * 1024.0);
|
|
}
|
|
return 0.0;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
public class InverseBooleanConverter : IValueConverter
|
|
{
|
|
public static readonly InverseBooleanConverter Instance = new();
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value is bool boolValue)
|
|
{
|
|
return !boolValue;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value is bool boolValue)
|
|
{
|
|
return !boolValue;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public class InverseBooleanToVisibilityConverter : IValueConverter
|
|
{
|
|
public static readonly InverseBooleanToVisibilityConverter Instance = new();
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value is bool boolValue)
|
|
{
|
|
return boolValue ? Visibility.Collapsed : Visibility.Visible;
|
|
}
|
|
return Visibility.Visible;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|
|
|