Merge core project into winui project.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
|
||||
namespace Wino.Converters;
|
||||
|
||||
public partial class GridLengthConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
if (value is double doubleValue)
|
||||
{
|
||||
return new GridLength(doubleValue);
|
||||
}
|
||||
return new GridLength(1, GridUnitType.Auto);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
if (value is GridLength gridLength)
|
||||
{
|
||||
return gridLength.Value;
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Microsoft.UI;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Windows.UI;
|
||||
|
||||
namespace Wino.Mail.WinUI.Converters;
|
||||
|
||||
public partial class HexToColorBrushConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
if (value is string hexColor && !string.IsNullOrEmpty(hexColor))
|
||||
{
|
||||
try
|
||||
{
|
||||
// Remove # if present
|
||||
hexColor = hexColor.Replace("#", "");
|
||||
|
||||
// Parse hex to color
|
||||
byte r = byte.Parse(hexColor.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
|
||||
byte g = byte.Parse(hexColor.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
|
||||
byte b = byte.Parse(hexColor.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
|
||||
|
||||
return new SolidColorBrush(Color.FromArgb(255, r, g, b));
|
||||
}
|
||||
catch
|
||||
{
|
||||
return GetDefaultBrush();
|
||||
}
|
||||
}
|
||||
|
||||
return GetDefaultBrush();
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
if (value is string hexColor)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Remove # if present
|
||||
hexColor = hexColor.Replace("#", string.Empty);
|
||||
|
||||
// Parse ARGB values
|
||||
byte a = 255; // Default to fully opaque
|
||||
byte r = byte.Parse(hexColor.Substring(0, 2), NumberStyles.HexNumber);
|
||||
byte g = byte.Parse(hexColor.Substring(2, 2), NumberStyles.HexNumber);
|
||||
byte b = byte.Parse(hexColor.Substring(4, 2), NumberStyles.HexNumber);
|
||||
|
||||
// If 8-digit hex (with alpha), parse alpha value
|
||||
if (hexColor.Length == 8)
|
||||
{
|
||||
a = byte.Parse(hexColor.Substring(6, 2), NumberStyles.HexNumber);
|
||||
}
|
||||
|
||||
return Color.FromArgb(a, r, g, b);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
|
||||
private SolidColorBrush GetDefaultBrush()
|
||||
{
|
||||
// Get current theme's foreground brush.
|
||||
// Bug: This should be ThemeResource to react to theme changes, but it's not.
|
||||
// So if user changes the dark/light theme, this won't update.
|
||||
|
||||
if (WinoApplication.Current.UnderlyingThemeService.IsUnderlyingThemeDark())
|
||||
return new SolidColorBrush(Colors.White);
|
||||
else
|
||||
return new SolidColorBrush(Colors.Black);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
|
||||
namespace Wino.Converters;
|
||||
|
||||
public partial class ReverseBooleanConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
if (value is bool boolval)
|
||||
return !boolval;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
|
||||
namespace Wino.Converters;
|
||||
|
||||
public partial class ReverseBooleanToVisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
return ((bool)value) ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user