- StorageView.xaml: DataGrid with IndentLevel-based name indentation - StorageView.xaml.cs: code-behind wiring DataContext to StorageViewModel - IndentConverter.cs: IndentConverter, BytesConverter, InverseBoolConverter - App.xaml: register converters and RightAlignStyle as Application.Resources - App.xaml.cs: register IStorageService, StorageCsvExportService, StorageHtmlExportService, StorageViewModel, StorageView - MainWindow.xaml: add x:Name=StorageTabItem to Storage TabItem - MainWindow.xaml.cs: wire StorageTabItem.Content from DI
48 lines
1.8 KiB
C#
48 lines
1.8 KiB
C#
using System.Globalization;
|
|
using System.Windows;
|
|
using System.Windows.Data;
|
|
|
|
namespace SharepointToolbox.Views.Converters;
|
|
|
|
/// <summary>Converts IndentLevel (int) to WPF Thickness for DataGrid indent.</summary>
|
|
[ValueConversion(typeof(int), typeof(Thickness))]
|
|
public class IndentConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
int level = value is int i ? i : 0;
|
|
return new Thickness(level * 16, 0, 0, 0);
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
=> throw new NotImplementedException();
|
|
}
|
|
|
|
/// <summary>Converts byte count (long) to human-readable size string.</summary>
|
|
[ValueConversion(typeof(long), typeof(string))]
|
|
public class BytesConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
long bytes = value is long l ? l : 0L;
|
|
if (bytes >= 1_073_741_824L) return $"{bytes / 1_073_741_824.0:F2} GB";
|
|
if (bytes >= 1_048_576L) return $"{bytes / 1_048_576.0:F2} MB";
|
|
if (bytes >= 1024L) return $"{bytes / 1024.0:F2} KB";
|
|
return $"{bytes} B";
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
=> throw new NotImplementedException();
|
|
}
|
|
|
|
/// <summary>Inverts a bool binding — used to disable controls while an operation is running.</summary>
|
|
[ValueConversion(typeof(bool), typeof(bool))]
|
|
public class InverseBoolConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
=> value is bool b && !b;
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
=> value is bool b && !b;
|
|
}
|