feat: implement JumpTo command in ApplicationViewModel and update navigation handling. (#803)
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
xmlns:semi="https://irihi.tech/semi"
|
||||
xmlns:u-semi="https://irihi.tech/ursa/themes/semi"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
xmlns:iri="https://irihi.tech/shared">
|
||||
xmlns:iri="https://irihi.tech/shared"
|
||||
xmlns:vm="clr-namespace:Ursa.Demo.ViewModels"
|
||||
x:DataType="vm:ApplicationViewModel">
|
||||
<Application.Styles>
|
||||
<semi:SemiTheme Locale="zh-CN" />
|
||||
<semi:SemiPopupAnimations />
|
||||
@@ -18,4 +20,12 @@
|
||||
</Style>
|
||||
</Style>
|
||||
</Application.Styles>
|
||||
<NativeMenu.Menu>
|
||||
<NativeMenu>
|
||||
<NativeMenuItem
|
||||
Header="About Us"
|
||||
Command="{Binding JumpToCommand}"
|
||||
CommandParameter="{x:Static vm:MenuKeys.MenuKeyAboutUs}"/>
|
||||
</NativeMenu>
|
||||
</NativeMenu.Menu>
|
||||
</Application>
|
||||
@@ -12,6 +12,7 @@ public partial class App : Application
|
||||
public override void Initialize()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
DataContext = new ApplicationViewModel();
|
||||
}
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
|
||||
14
demo/Ursa.Demo/ViewModels/ApplicationViewModel.cs
Normal file
14
demo/Ursa.Demo/ViewModels/ApplicationViewModel.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
|
||||
namespace Ursa.Demo.ViewModels;
|
||||
|
||||
public partial class ApplicationViewModel : ObservableObject
|
||||
{
|
||||
[RelayCommand]
|
||||
private void JumpTo(string header)
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(header, "JumpTo");
|
||||
}
|
||||
}
|
||||
@@ -16,17 +16,12 @@ public partial class MainViewViewModel : ViewModelBase
|
||||
public WindowNotificationManager? NotificationManager { get; set; }
|
||||
public MenuViewModel Menus { get; set; } = new MenuViewModel();
|
||||
|
||||
private object? _content;
|
||||
|
||||
public object? Content
|
||||
{
|
||||
get => _content;
|
||||
set => SetProperty(ref _content, value);
|
||||
}
|
||||
[ObservableProperty] private object? _content;
|
||||
|
||||
public MainViewViewModel()
|
||||
{
|
||||
WeakReferenceMessenger.Default.Register<MainViewViewModel, string>(this, OnNavigation);
|
||||
WeakReferenceMessenger.Default.Register<MainViewViewModel, string, string>(this, "JumpTo", OnNavigation);
|
||||
OnNavigation(this, MenuKeys.MenuKeyIntroduction);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -32,6 +32,6 @@ public class MenuItemViewModel: ViewModelBase
|
||||
private void OnActivate()
|
||||
{
|
||||
if (IsSeparator || Key is null) return;
|
||||
WeakReferenceMessenger.Default.Send(Key);
|
||||
WeakReferenceMessenger.Default.Send(Key, "JumpTo");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user