Parameter improvements
This commit is contained in:
@@ -5,4 +5,4 @@ namespace Toolkit.UI.Avalonia;
|
||||
public class ConditionCollection :
|
||||
ObservableCollection<ComparisonCondition>
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Metadata;
|
||||
using Avalonia.Xaml.Interactivity;
|
||||
using System.Collections.Immutable;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Toolkit.UI.Avalonia;
|
||||
@@ -10,12 +11,9 @@ public class NavigateAction :
|
||||
AvaloniaObject,
|
||||
IAction
|
||||
{
|
||||
public static readonly DirectProperty<NavigateAction, ParameterBindingCollection> ParameterBindingsProperty =
|
||||
AvaloniaProperty.RegisterDirect<NavigateAction, ParameterBindingCollection>(nameof(ParameterBindings),
|
||||
x => x.ParameterBindings);
|
||||
|
||||
public static readonly StyledProperty<object[]?> ParametersProperty =
|
||||
AvaloniaProperty.Register<NavigateAction, object[]?>(nameof(Parameters));
|
||||
public static readonly DirectProperty<NavigateAction, ParameterCollection> ParametersProperty =
|
||||
AvaloniaProperty.RegisterDirect<NavigateAction, ParameterCollection>(nameof(Parameters),
|
||||
x => x.Parameters);
|
||||
|
||||
public static readonly StyledProperty<object> RegionProperty =
|
||||
AvaloniaProperty.Register<NavigateAction, object>(nameof(Region));
|
||||
@@ -26,7 +24,7 @@ public class NavigateAction :
|
||||
public static readonly StyledProperty<string> ScopeProperty =
|
||||
AvaloniaProperty.Register<NavigateAction, string>(nameof(Scope));
|
||||
|
||||
private ParameterBindingCollection parameterCollection = [];
|
||||
private ParameterCollection parameterCollection = [];
|
||||
|
||||
public event EventHandler? Navigated;
|
||||
|
||||
@@ -37,15 +35,9 @@ public class NavigateAction :
|
||||
}
|
||||
|
||||
[Content]
|
||||
public ParameterBindingCollection ParameterBindings =>
|
||||
public ParameterCollection Parameters =>
|
||||
parameterCollection ??= [];
|
||||
|
||||
public object[]? Parameters
|
||||
{
|
||||
get => GetValue(ParametersProperty);
|
||||
set => SetValue(ParametersProperty, value);
|
||||
}
|
||||
|
||||
public string Route
|
||||
{
|
||||
get => GetValue(RouteProperty);
|
||||
@@ -68,11 +60,8 @@ public class NavigateAction :
|
||||
|
||||
if (content.DataContext is IObservableViewModel observableViewModel)
|
||||
{
|
||||
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>>()];
|
||||
ImmutableDictionary<string, object>? parameters = Parameters is { Count: > 0 } ? Parameters.ToImmutableDictionary(x => x.Key, x => x.Value) :
|
||||
ImmutableDictionary<string, object>.Empty;
|
||||
|
||||
observableViewModel.Publisher.Publish(new NavigateEventArgs(Route, Region == this ? content : Region, Scope ?? null,
|
||||
content.DataContext, Navigated, parameters));
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
namespace Toolkit.UI.Avalonia;
|
||||
|
||||
public class ParameterBinding :
|
||||
public class Parameter :
|
||||
AvaloniaObject
|
||||
{
|
||||
public static readonly StyledProperty<string> KeyProperty =
|
||||
AvaloniaProperty.Register<ParameterBinding, string>(nameof(Key));
|
||||
AvaloniaProperty.Register<Parameter, string>(nameof(Key));
|
||||
|
||||
public static readonly StyledProperty<object> ValueProperty =
|
||||
AvaloniaProperty.Register<ParameterBinding, object>(nameof(Value));
|
||||
AvaloniaProperty.Register<Parameter, object>(nameof(Value));
|
||||
|
||||
public string Key
|
||||
{
|
||||
@@ -1,6 +0,0 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Toolkit.UI.Avalonia;
|
||||
|
||||
public class ParameterBindingCollection :
|
||||
ObservableCollection<ParameterBinding>;
|
||||
@@ -0,0 +1,6 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Toolkit.UI.Avalonia;
|
||||
|
||||
public class ParameterCollection :
|
||||
ObservableCollection<Parameter>;
|
||||
Reference in New Issue
Block a user