Improved NavigationViewExtension
This commit is contained in:
@@ -4,8 +4,7 @@ namespace Toolkit.Foundation;
|
|||||||
|
|
||||||
public partial class ComponentConfigurationViewModel<TConfiguration, TValue, THeader, TDescription, TAction> :
|
public partial class ComponentConfigurationViewModel<TConfiguration, TValue, THeader, TDescription, TAction> :
|
||||||
ValueViewModel<TValue>,
|
ValueViewModel<TValue>,
|
||||||
IComponentConfigurationViewModel,
|
IComponentConfigurationViewModel
|
||||||
INotificationHandler<ChangedEventArgs<TConfiguration>>
|
|
||||||
where TConfiguration : class
|
where TConfiguration : class
|
||||||
{
|
{
|
||||||
public ComponentConfigurationViewModel(IServiceProvider provider,
|
public ComponentConfigurationViewModel(IServiceProvider provider,
|
||||||
@@ -19,11 +18,6 @@ public partial class ComponentConfigurationViewModel<TConfiguration, TValue, THe
|
|||||||
TAction action) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
TAction action) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Handle(ChangedEventArgs<TConfiguration> args)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial class ComponentConfigurationViewModel<TConfiguration, TValue, TAction>(IServiceProvider provider,
|
public partial class ComponentConfigurationViewModel<TConfiguration, TValue, TAction>(IServiceProvider provider,
|
||||||
|
|||||||
@@ -8,16 +8,11 @@ public class NamedTypeConverter :
|
|||||||
MarkupExtension,
|
MarkupExtension,
|
||||||
IValueConverter
|
IValueConverter
|
||||||
{
|
{
|
||||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
|
||||||
{
|
value is not null ? value.GetType().Name : (object?)null;
|
||||||
var d = value is not null ? value.GetType().Name : (object?)null;
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) =>
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
|
||||||
|
|
||||||
public override object ProvideValue(IServiceProvider serviceProvider) => this;
|
public override object ProvideValue(IServiceProvider serviceProvider) => this;
|
||||||
}
|
}
|
||||||
@@ -27,15 +27,14 @@ public class NavigationViewExtension
|
|||||||
{
|
{
|
||||||
if (sender.GetLogicalAncestors().OfType<NavigationView>().FirstOrDefault() is NavigationView navigationView)
|
if (sender.GetLogicalAncestors().OfType<NavigationView>().FirstOrDefault() is NavigationView navigationView)
|
||||||
{
|
{
|
||||||
void OnItemInvoked(object? _, FluentAvalonia.UI.Controls.NavigationViewItemInvokedEventArgs args)
|
sender.GetObservable(NavigationViewItem.IsSelectedProperty).Subscribe(args =>
|
||||||
{
|
{
|
||||||
if (args.InvokedItemContainer == sender)
|
if (args)
|
||||||
{
|
{
|
||||||
sender.RaiseEvent(new ItemInvokedEventArgs { RoutedEvent = ItemInvokedEvent });
|
sender.RaiseEvent(new ItemInvokedEventArgs { RoutedEvent = ItemInvokedEvent });
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
navigationView.ItemInvoked += OnItemInvoked;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,13 +43,12 @@ public class NavigationViewExtension
|
|||||||
|
|
||||||
if (!TrySetupNavigationView())
|
if (!TrySetupNavigationView())
|
||||||
{
|
{
|
||||||
void OnAttachedToVisualTree(object? _, VisualTreeAttachmentEventArgs __)
|
void HandleLoaded(object? _, RoutedEventArgs __)
|
||||||
{
|
{
|
||||||
sender.AttachedToVisualTree -= OnAttachedToVisualTree;
|
|
||||||
TrySetupNavigationView();
|
TrySetupNavigationView();
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.AttachedToVisualTree += OnAttachedToVisualTree;
|
sender.Loaded += HandleLoaded;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user