tidy
This commit is contained in:
@@ -9,4 +9,4 @@ public class AttachedBehavior : Trigger
|
||||
Interaction.ExecuteActions(AssociatedObject, Actions, null);
|
||||
base.OnAttachedToVisualTree();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,8 @@ using Avalonia.Xaml.Interactivity;
|
||||
|
||||
namespace Toolkit.UI.Avalonia;
|
||||
|
||||
public class ComparisonCondition :
|
||||
AvaloniaObject,
|
||||
public class ComparisonCondition :
|
||||
AvaloniaObject,
|
||||
ICondition
|
||||
{
|
||||
public static readonly StyledProperty<object> LeftOperandProperty =
|
||||
@@ -36,4 +36,4 @@ public class ComparisonCondition :
|
||||
|
||||
public bool Evaluate() => ComparisonLogic.Evaluate(LeftOperand,
|
||||
Operator, RightOperand);
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,8 @@ namespace Toolkit.UI.Avalonia;
|
||||
|
||||
internal static class ComparisonLogic
|
||||
{
|
||||
internal static bool Evaluate(object leftOperand,
|
||||
ComparisonConditionType operatorType,
|
||||
internal static bool Evaluate(object leftOperand,
|
||||
ComparisonConditionType operatorType,
|
||||
object? rightOperand)
|
||||
{
|
||||
bool result = false;
|
||||
@@ -17,14 +17,13 @@ internal static class ComparisonLogic
|
||||
Type leftType = leftOperand.GetType();
|
||||
|
||||
if (rightOperand != null)
|
||||
{
|
||||
{
|
||||
TypeConverter typeConverter = TypeDescriptor.GetConverter(leftType);
|
||||
rightOperand = typeConverter.ConvertFrom(rightOperand);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (leftOperand is IComparable leftComparableOperand &&
|
||||
if (leftOperand is IComparable leftComparableOperand &&
|
||||
rightOperand is IComparable rightComparableOperand)
|
||||
{
|
||||
return EvaluateComparable(leftComparableOperand, operatorType, rightComparableOperand);
|
||||
@@ -35,6 +34,7 @@ internal static class ComparisonLogic
|
||||
case ComparisonConditionType.Equal:
|
||||
result = Equals(leftOperand, rightOperand);
|
||||
break;
|
||||
|
||||
case ComparisonConditionType.NotEqual:
|
||||
result = !Equals(leftOperand, rightOperand);
|
||||
break;
|
||||
@@ -43,7 +43,7 @@ internal static class ComparisonLogic
|
||||
}
|
||||
|
||||
private static bool EvaluateComparable(IComparable leftOperand,
|
||||
ComparisonConditionType operatorType,
|
||||
ComparisonConditionType operatorType,
|
||||
IComparable rightOperand)
|
||||
{
|
||||
object? convertedOperand = null;
|
||||
@@ -54,11 +54,9 @@ internal static class ComparisonLogic
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
|
||||
}
|
||||
catch (InvalidCastException)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (convertedOperand == null)
|
||||
@@ -74,18 +72,23 @@ internal static class ComparisonLogic
|
||||
case ComparisonConditionType.Equal:
|
||||
result = comparison == 0;
|
||||
break;
|
||||
|
||||
case ComparisonConditionType.GreaterThan:
|
||||
result = comparison > 0;
|
||||
break;
|
||||
|
||||
case ComparisonConditionType.GreaterThanOrEqual:
|
||||
result = comparison >= 0;
|
||||
break;
|
||||
|
||||
case ComparisonConditionType.LessThan:
|
||||
result = comparison < 0;
|
||||
break;
|
||||
|
||||
case ComparisonConditionType.LessThanOrEqual:
|
||||
result = comparison <= 0;
|
||||
break;
|
||||
|
||||
case ComparisonConditionType.NotEqual:
|
||||
result = comparison != 0;
|
||||
break;
|
||||
@@ -93,4 +96,4 @@ internal static class ComparisonLogic
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using Avalonia.Xaml.Interactivity;
|
||||
|
||||
namespace Toolkit.UI.Avalonia;
|
||||
|
||||
public class ConditionAction :
|
||||
public class ConditionAction :
|
||||
AvaloniaObject,
|
||||
IAction
|
||||
{
|
||||
|
||||
@@ -5,4 +5,4 @@ namespace Toolkit.UI.Avalonia;
|
||||
public class ConditionCollection :
|
||||
ObservableCollection<ComparisonCondition>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Metadata;
|
||||
using Toolkit.UI.Avalonia;
|
||||
|
||||
namespace Toolkit.UI.Avalonia;
|
||||
|
||||
public class ConditionalExpression :
|
||||
public class ConditionalExpression :
|
||||
AvaloniaObject,
|
||||
ICondition
|
||||
{
|
||||
@@ -18,7 +17,7 @@ public class ConditionalExpression :
|
||||
SetValue(ConditionsProperty, []);
|
||||
|
||||
[Content]
|
||||
public ConditionCollection Conditions =>
|
||||
public ConditionCollection Conditions =>
|
||||
GetValue(ConditionsProperty);
|
||||
|
||||
public ForwardChaining ForwardChaining
|
||||
@@ -47,4 +46,4 @@ public class ConditionalExpression :
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,4 +4,4 @@ public enum ForwardChaining
|
||||
{
|
||||
And,
|
||||
Or
|
||||
}
|
||||
}
|
||||
@@ -3,4 +3,4 @@
|
||||
public interface ICondition
|
||||
{
|
||||
bool Evaluate();
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@ using System.Windows.Input;
|
||||
|
||||
namespace Toolkit.UI.Avalonia;
|
||||
|
||||
public class KeyBindingTriggerBehavior :
|
||||
Trigger<InputElement>,
|
||||
public class KeyBindingTriggerBehavior :
|
||||
Trigger<InputElement>,
|
||||
ICommand
|
||||
{
|
||||
public static readonly StyledProperty<KeyGesture> GestureProperty =
|
||||
@@ -38,6 +38,6 @@ public class KeyBindingTriggerBehavior :
|
||||
|
||||
public bool CanExecute(object? parameter) => true;
|
||||
|
||||
public void Execute(object? parameter) =>
|
||||
public void Execute(object? parameter) =>
|
||||
Interaction.ExecuteActions(AssociatedObject, Actions, null);
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,7 @@ public class NavigateAction :
|
||||
get => GetValue(RouteProperty);
|
||||
set => SetValue(RouteProperty, value);
|
||||
}
|
||||
|
||||
public string Scope
|
||||
{
|
||||
get => GetValue(ScopeProperty);
|
||||
@@ -62,12 +63,13 @@ public class NavigateAction :
|
||||
{
|
||||
if (sender is TemplatedControl control)
|
||||
{
|
||||
Dictionary<string, object> arguments =
|
||||
Dictionary<string, object> arguments =
|
||||
new(StringComparer.InvariantCultureIgnoreCase);
|
||||
|
||||
if (control.DataContext is IObservableViewModel observableViewModel)
|
||||
{
|
||||
object[] parameters = [.. Parameters ?? Enumerable.Empty<object?>(), ..
|
||||
object[] parameters = [.. Parameters ?? Enumerable.Empty<object?>(),
|
||||
..
|
||||
ParameterBindings is { Count: > 0 } ?
|
||||
ParameterBindings.Select(binding => new KeyValuePair<string, object>(binding.Key, binding.Value)).ToArray() :
|
||||
Enumerable.Empty<KeyValuePair<string, object>>()];
|
||||
@@ -79,4 +81,4 @@ public class NavigateAction :
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,4 +41,4 @@ public class NavigateBackAction :
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,10 @@ public class ParameterBinding :
|
||||
get => GetValue(KeyProperty);
|
||||
set => SetValue(KeyProperty, value);
|
||||
}
|
||||
|
||||
public object Value
|
||||
{
|
||||
get => GetValue(ValueProperty);
|
||||
set => SetValue(ValueProperty, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user