This commit is contained in:
TheXamlGuy
2024-07-10 14:36:09 +01:00
parent 5ce415eb3d
commit 3dfe0ce59b
5 changed files with 73 additions and 33 deletions
+19 -14
View File
@@ -10,8 +10,7 @@
FooterMenuItemsSource="{Binding Footer}" FooterMenuItemsSource="{Binding Footer}"
IsSettingsVisible="False" IsSettingsVisible="False"
MenuItemTemplate="{Binding Template}" MenuItemTemplate="{Binding Template}"
MenuItemsSource="{Binding SelectedItem}" MenuItemsSource="{Binding #ListBox.SelectedItem}">
SelectionFollowsFocus="True">
<Interaction.Behaviors> <Interaction.Behaviors>
<DataTriggerBehavior Binding="{ReflectionBinding SelectedItem.IsOpened}" Value="True"> <DataTriggerBehavior Binding="{ReflectionBinding SelectedItem.IsOpened}" Value="True">
<InvokeNavigationViewItemAction SelectedIndex="1" /> <InvokeNavigationViewItemAction SelectedIndex="1" />
@@ -31,19 +30,19 @@
<TextBlock <TextBlock
FontSize="10" FontSize="10"
Foreground="{DynamicResource TextOnAccentFillColorPrimaryBrush}" Foreground="{DynamicResource TextOnAccentFillColorPrimaryBrush}"
Text="BETA PREVIEW 3" /> Text="{ReflectionBinding SelectedItem.Name}" />
</Border> </Border>
</NavigationView.PaneHeader> </NavigationView.PaneHeader>
<NavigationView.PaneCustomContent> <NavigationView.PaneCustomContent>
<Grid RowDefinitions="*,Auto"> <Grid RowDefinitions="*,Auto">
<OverflowListBox <Overflow
x:Name="ListBox" x:Name="ListBox"
Grid.Row="0" Grid.Row="0"
HorizontalAlignment="Center" HorizontalAlignment="Center"
ItemTemplate="{ReflectionBinding Template}" ItemTemplate="{ReflectionBinding Template}"
ItemsSource="{Binding}" ItemsSource="{Binding}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"> SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
<OverflowListBox.Resources> <Overflow.Resources>
<StaticResource x:Key="ListViewItemBackgroundSelected" ResourceKey="SubtleFillColorTransparentBrush" /> <StaticResource x:Key="ListViewItemBackgroundSelected" ResourceKey="SubtleFillColorTransparentBrush" />
<x:Double x:Key="WalletItemSize">40</x:Double> <x:Double x:Key="WalletItemSize">40</x:Double>
<CornerRadius x:Key="WalletItemCornerRadius">40</CornerRadius> <CornerRadius x:Key="WalletItemCornerRadius">40</CornerRadius>
@@ -146,26 +145,26 @@
</Style> </Style>
</Style> </Style>
</ControlTheme> </ControlTheme>
</OverflowListBox.Resources> </Overflow.Resources>
<OverflowListBox.Styles> <Overflow.Styles>
<Style Selector="OverflowListBox.Closed"> <Style Selector="Overflow.Closed">
<Setter Property="Margin" Value="1,2,1,0" /> <Setter Property="Margin" Value="1,2,1,0" />
<Style Selector="^ StackPanel"> <Style Selector="^ StackPanel">
<Setter Property="Orientation" Value="Vertical" /> <Setter Property="Orientation" Value="Vertical" />
</Style> </Style>
</Style> </Style>
<Style Selector="OverflowListBox.Opened"> <Style Selector="Overflow.Opened">
<Setter Property="Margin" Value="12,2,12,0" /> <Setter Property="Margin" Value="12,2,12,0" />
<Style Selector="^ StackPanel"> <Style Selector="^ StackPanel">
<Setter Property="Orientation" Value="Horizontal" /> <Setter Property="Orientation" Value="Horizontal" />
</Style> </Style>
</Style> </Style>
</OverflowListBox.Styles> </Overflow.Styles>
<OverflowListBox.ItemsPanel> <Overflow.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
<StackPanel Spacing="6" /> <StackPanel Spacing="6" />
</ItemsPanelTemplate> </ItemsPanelTemplate>
</OverflowListBox.ItemsPanel> </Overflow.ItemsPanel>
<Interaction.Behaviors> <Interaction.Behaviors>
<DataTriggerBehavior Binding="{Binding $parent[NavigationView].IsPaneOpen}" Value="True"> <DataTriggerBehavior Binding="{Binding $parent[NavigationView].IsPaneOpen}" Value="True">
<AddClassAction ClassName="Opened" RemoveIfExists="True" /> <AddClassAction ClassName="Opened" RemoveIfExists="True" />
@@ -175,14 +174,20 @@
<AddClassAction ClassName="Closed" RemoveIfExists="True" /> <AddClassAction ClassName="Closed" RemoveIfExists="True" />
<RemoveClassAction ClassName="Opened" /> <RemoveClassAction ClassName="Opened" />
</DataTriggerBehavior> </DataTriggerBehavior>
<DataTriggerBehavior Binding="{Binding $parent[NavigationView].SelectedItem, Converter={NamedTypeConverter}}" Value="ManageNavigationViewModel"> <DataTriggerBehavior Binding="{Binding #ListBox.SelectedItem, Converter={NamedTypeConverter}}" Value="WalletNavigationViewModel">
<ChangePropertyAction
PropertyName="SelectedItem"
TargetObject="{Binding #NavigationView}"
Value="{x:Null}" />
</DataTriggerBehavior>
<DataTriggerBehavior Binding="{Binding #NavigationView.SelectedItem, Converter={NamedTypeConverter}}" Value="ManageNavigationViewModel">
<ChangePropertyAction <ChangePropertyAction
PropertyName="SelectedItem" PropertyName="SelectedItem"
TargetObject="{Binding #ListBox}" TargetObject="{Binding #ListBox}"
Value="{x:Null}" /> Value="{x:Null}" />
</DataTriggerBehavior> </DataTriggerBehavior>
</Interaction.Behaviors> </Interaction.Behaviors>
</OverflowListBox> </Overflow>
<NavigationViewItemSeparator Grid.Row="1" /> <NavigationViewItemSeparator Grid.Row="1" />
</Grid> </Grid>
</NavigationView.PaneCustomContent> </NavigationView.PaneCustomContent>
@@ -12,19 +12,6 @@
<CornerRadius x:Key="IconCornerRadius">40</CornerRadius> <CornerRadius x:Key="IconCornerRadius">40</CornerRadius>
</ListBoxItem.Resources> </ListBoxItem.Resources>
<Interaction.Behaviors> <Interaction.Behaviors>
<DataTriggerBehavior Binding="{Binding IsOpened}" Value="False">
<ConditionAction>
<ConditionAction.Condition>
<ConditionalExpression ForwardChaining="And">
<ComparisonCondition LeftOperand="{Binding IsSelected}" RightOperand="True" />
</ConditionalExpression>
</ConditionAction.Condition>
<NavigateAction Region="Main" Route="OpenWallet">
<Parameter Key="Name" Value="{Binding Name}" />
<Parameter Key="ImageDescriptor" Value="{Binding ImageDescriptor}" />
</NavigateAction>
</ConditionAction>
</DataTriggerBehavior>
<AttachedEventTriggerBehaviour RoutedEvent="{x:Static ListBoxExtension.ItemInvokedEvent}"> <AttachedEventTriggerBehaviour RoutedEvent="{x:Static ListBoxExtension.ItemInvokedEvent}">
<ConditionAction> <ConditionAction>
<ConditionAction.Condition> <ConditionAction.Condition>
+18 -2
View File
@@ -11,8 +11,24 @@ public class MainViewModelActivationHandler(IPublisher publisher,
{ {
bool selected = true; bool selected = true;
foreach (IComponentHost Wallet in Wallets.OrderBy(x => x.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>() foreach (IComponentHost Wallet in Wallets.OrderBy(x =>
is IConfigurationDescriptor<WalletConfiguration> descriptor ? descriptor.Name : null)) {
IConfigurationDescriptor<WalletConfiguration> descriptor = x.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>();
return descriptor?.Name;
},
Comparer<string?>.Create((x, y) =>
{
bool xIsNumeric = int.TryParse(x, out int xNum);
bool yIsNumeric = int.TryParse(y, out int yNum);
return (xIsNumeric, yIsNumeric) switch
{
(true, true) => xNum.CompareTo(yNum),
(true, false) => -1,
(false, true) => 1,
_ => string.Compare(x, y, StringComparison.Ordinal)
};
})))
{ {
if (Wallet.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>() if (Wallet.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>()
is IConfigurationDescriptor<WalletConfiguration> configuration) is IConfigurationDescriptor<WalletConfiguration> configuration)
+13
View File
@@ -50,4 +50,17 @@ public partial class OpenWalletViewModel :
} }
} }
} }
//public override async Task OnActivated()
//{
// Publisher.Publish(Activated.As<Wallet>());
// await base.OnActivated();
//}
//public override async Task OnDeactivated()
//{
// Publisher.Publish(Deactivated.As<Wallet>());
// await base.OnDeactivated();
//}
} }
+21 -2
View File
@@ -11,8 +11,27 @@ public class WalletActivatedHandler(IWalletHostCollection wallets,
{ {
if (args.Sender is Wallet<IComponentHost> wallet && wallet.Value is IComponentHost host) if (args.Sender is Wallet<IComponentHost> wallet && wallet.Value is IComponentHost host)
{ {
List<IComponentHost> sortedWallets = [.. wallets.OrderBy(x => x.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>() is List<IComponentHost> sortedWallets =
IConfigurationDescriptor<WalletConfiguration> descriptor ? descriptor.Name : null)]; [
.. wallets.OrderBy(wallet =>
{
var descriptor = wallet.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>();
return descriptor?.Name;
},
Comparer<string?>.Create((x, y) =>
{
bool xIsNumeric = int.TryParse(x, out int xNum);
bool yIsNumeric = int.TryParse(y, out int yNum);
return (xIsNumeric, yIsNumeric) switch
{
(true, true) => xNum.CompareTo(yNum),
(true, false) => -1,
(false, true) => 1,
_ => string.Compare(x, y, StringComparison.Ordinal)
};
})),
];
int index = sortedWallets.IndexOf(host); int index = sortedWallets.IndexOf(host);