Add project files.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace Nodify
|
||||
{
|
||||
public class BooleanToVisibilityConverter : MarkupExtension, IValueConverter
|
||||
{
|
||||
public Visibility FalseVisibility { get; set; } = Visibility.Collapsed;
|
||||
public bool Negate { get; set; }
|
||||
|
||||
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
string? stringValue = value?.ToString();
|
||||
if (bool.TryParse(stringValue, out var b))
|
||||
{
|
||||
return (Negate ? !b : b) ? Visibility.Visible : FalseVisibility;
|
||||
}
|
||||
else if (double.TryParse(stringValue, out var d))
|
||||
{
|
||||
return (Negate ? !(d > 0) : (d > 0)) ? Visibility.Visible : FalseVisibility;
|
||||
}
|
||||
|
||||
bool result = value != null;
|
||||
return (Negate ? !result : result) ? Visibility.Visible : FalseVisibility;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
=> value is Visibility v && v == Visibility.Visible;
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider) => this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Nodify
|
||||
{
|
||||
public class ColorToSolidColorBrushConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is Color color)
|
||||
{
|
||||
var brush = new SolidColorBrush(color);
|
||||
|
||||
if(double.TryParse(parameter?.ToString(), out double opacity))
|
||||
brush.Opacity = opacity;
|
||||
|
||||
return brush;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is SolidColorBrush brush)
|
||||
return brush.Color;
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
Examples/Nodify.Shared/Converters/DebugConverter.cs
Normal file
24
Examples/Nodify.Shared/Converters/DebugConverter.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace Nodify
|
||||
{
|
||||
public class DebugConverter : MarkupExtension, IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
Console.WriteLine($"Value: {value} :: Parameter: {parameter}");
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
Console.WriteLine($"Value: {value} :: Parameter: {parameter}");
|
||||
return value;
|
||||
}
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider) => this;
|
||||
}
|
||||
}
|
||||
49
Examples/Nodify.Shared/Converters/EnumValuesConverter.cs
Normal file
49
Examples/Nodify.Shared/Converters/EnumValuesConverter.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace Nodify
|
||||
{
|
||||
public readonly struct EnumValue
|
||||
{
|
||||
public EnumValue(string name, object? value)
|
||||
{
|
||||
Name = name;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
public object? Value { get; }
|
||||
}
|
||||
|
||||
public class EnumValuesConverter : MarkupExtension, IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is Enum enumValue)
|
||||
{
|
||||
var type = enumValue.GetType();
|
||||
var values = Enum.GetValues(type);
|
||||
var names = Enum.GetNames(type);
|
||||
|
||||
EnumValue[] result = new EnumValue[values.Length];
|
||||
for (int i = 0; i < values.Length; i++)
|
||||
{
|
||||
result[i] = new EnumValue(names[i], values.GetValue(i));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider) => this;
|
||||
}
|
||||
}
|
||||
25
Examples/Nodify.Shared/Converters/InverseBooleanConverter.cs
Normal file
25
Examples/Nodify.Shared/Converters/InverseBooleanConverter.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Nodify
|
||||
{
|
||||
public class InverseBooleanConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (targetType != typeof(bool))
|
||||
throw new InvalidOperationException("The value must be of type bool.");
|
||||
|
||||
return !(bool)value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (targetType != typeof(bool))
|
||||
throw new InvalidOperationException("The value must be of type bool.");
|
||||
|
||||
return !(bool)value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Nodify
|
||||
{
|
||||
public class MultiValueEqualityConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (values == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return AllElementsEqual(values) || AllElementsNull(values);
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private static bool AllElementsEqual(IEnumerable<object> values)
|
||||
{
|
||||
object? firstElement = values.FirstOrDefault();
|
||||
return values.All(o => o?.Equals(firstElement) == true);
|
||||
}
|
||||
|
||||
private static bool AllElementsNull(IEnumerable<object> values)
|
||||
{
|
||||
return values.All(o => o == null);
|
||||
}
|
||||
}
|
||||
}
|
||||
30
Examples/Nodify.Shared/Converters/RandomBrushConverter.cs
Normal file
30
Examples/Nodify.Shared/Converters/RandomBrushConverter.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Nodify
|
||||
{
|
||||
public class RandomBrushConverter : IValueConverter
|
||||
{
|
||||
private readonly Random _rand = new Random();
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (double.TryParse(parameter?.ToString(), out double alpha))
|
||||
{
|
||||
return new SolidColorBrush(Color.FromRgb((byte)_rand.Next(256), (byte)_rand.Next(256), (byte)_rand.Next(256)))
|
||||
{
|
||||
Opacity = alpha
|
||||
};
|
||||
}
|
||||
|
||||
return new SolidColorBrush(Color.FromRgb((byte)_rand.Next(256), (byte)_rand.Next(256), (byte)_rand.Next(256)));
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Nodify
|
||||
{
|
||||
internal class ResizeDirectionToVisiblityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (!(value is ResizeDirections resizeDirections))
|
||||
{
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
|
||||
if (Enum.TryParse(parameter.ToString(), out ResizeDirections direction))
|
||||
{
|
||||
return resizeDirections.HasFlag(direction) ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace Nodify
|
||||
{
|
||||
public class StringToVisibilityConverter : MarkupExtension, IValueConverter
|
||||
{
|
||||
public Visibility NullVisibility { get; set; } = Visibility.Collapsed;
|
||||
|
||||
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
=> string.IsNullOrEmpty(value as string) ? NullVisibility : Visibility.Visible;
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider) => this;
|
||||
}
|
||||
}
|
||||
35
Examples/Nodify.Shared/Converters/ToStringConverter.cs
Normal file
35
Examples/Nodify.Shared/Converters/ToStringConverter.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Nodify
|
||||
{
|
||||
public class ToStringConverter : IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is Point p)
|
||||
{
|
||||
return $"{p.X:0.0}, {p.Y:0.0}";
|
||||
}
|
||||
|
||||
if (value is Size s)
|
||||
{
|
||||
return $"{s.Width:0.0}, {s.Height:0.0}";
|
||||
}
|
||||
|
||||
if(value is double d)
|
||||
{
|
||||
return d.ToString("0.00");
|
||||
}
|
||||
|
||||
return value?.ToString();
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user