diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 447eca792..07b721b99 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -64,6 +64,7 @@ namespace Flow.Launcher .AddSingleton() .AddSingleton() .AddSingleton() + .AddSingleton() ).Build(); Ioc.Default.ConfigureServices(host.Services); } diff --git a/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs index 8d4312ba5..880bfd9bc 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage1.xaml.cs @@ -3,6 +3,7 @@ using System.Windows.Navigation; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Core.Resource; using CommunityToolkit.Mvvm.DependencyInjection; +using Flow.Launcher.ViewModel; namespace Flow.Launcher.Resources.Pages { @@ -11,6 +12,9 @@ namespace Flow.Launcher.Resources.Pages protected override void OnNavigatedTo(NavigationEventArgs e) { Settings = Ioc.Default.GetRequiredService(); + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page number + Ioc.Default.GetRequiredService().PageNum = 1; InitializeComponent(); } private Internationalization _translater => InternationalizationManager.Instance; diff --git a/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs index 4a4679a4a..786b4d506 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage2.xaml.cs @@ -16,6 +16,9 @@ namespace Flow.Launcher.Resources.Pages protected override void OnNavigatedTo(NavigationEventArgs e) { Settings = Ioc.Default.GetRequiredService(); + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page number + Ioc.Default.GetRequiredService().PageNum = 2; InitializeComponent(); } diff --git a/Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs index 38cb8642a..f59b65c1c 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage3.xaml.cs @@ -1,6 +1,7 @@ using System.Windows.Navigation; using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.Infrastructure.UserSettings; +using Flow.Launcher.ViewModel; namespace Flow.Launcher.Resources.Pages { @@ -9,6 +10,9 @@ namespace Flow.Launcher.Resources.Pages protected override void OnNavigatedTo(NavigationEventArgs e) { Settings = Ioc.Default.GetRequiredService(); + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page number + Ioc.Default.GetRequiredService().PageNum = 3; InitializeComponent(); } diff --git a/Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs index fc6568935..4c83f3a83 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage4.xaml.cs @@ -1,5 +1,6 @@ using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.Infrastructure.UserSettings; +using Flow.Launcher.ViewModel; using System.Windows.Navigation; namespace Flow.Launcher.Resources.Pages @@ -9,6 +10,9 @@ namespace Flow.Launcher.Resources.Pages protected override void OnNavigatedTo(NavigationEventArgs e) { Settings = Ioc.Default.GetRequiredService(); + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page number + Ioc.Default.GetRequiredService().PageNum = 4; InitializeComponent(); } diff --git a/Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs b/Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs index 5327eb5c8..95d7ff1a0 100644 --- a/Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs +++ b/Flow.Launcher/Resources/Pages/WelcomePage5.xaml.cs @@ -4,6 +4,7 @@ using Flow.Launcher.Infrastructure.UserSettings; using Microsoft.Win32; using Flow.Launcher.Infrastructure; using CommunityToolkit.Mvvm.DependencyInjection; +using Flow.Launcher.ViewModel; namespace Flow.Launcher.Resources.Pages { @@ -16,6 +17,9 @@ namespace Flow.Launcher.Resources.Pages protected override void OnNavigatedTo(NavigationEventArgs e) { Settings = Ioc.Default.GetRequiredService(); + // Sometimes the navigation is not triggered by button click, + // so we need to reset the page number + Ioc.Default.GetRequiredService().PageNum = 5; InitializeComponent(); } diff --git a/Flow.Launcher/ViewModel/WelcomeViewModel.cs b/Flow.Launcher/ViewModel/WelcomeViewModel.cs new file mode 100644 index 000000000..5eecabfde --- /dev/null +++ b/Flow.Launcher/ViewModel/WelcomeViewModel.cs @@ -0,0 +1,68 @@ +using Flow.Launcher.Plugin; + +namespace Flow.Launcher.ViewModel +{ + public partial class WelcomeViewModel : BaseModel + { + public const int MaxPageNum = 5; + + public string PageDisplay => $"{PageNum}/5"; + + private int _pageNum = 1; + public int PageNum + { + get => _pageNum; + set + { + if (_pageNum != value) + { + _pageNum = value; + OnPropertyChanged(); + UpdateView(); + } + } + } + + private bool _backEnabled = false; + public bool BackEnabled + { + get => _backEnabled; + set + { + _backEnabled = value; + OnPropertyChanged(); + } + } + + private bool _nextEnabled = true; + public bool NextEnabled + { + get => _nextEnabled; + set + { + _nextEnabled = value; + OnPropertyChanged(); + } + } + + private void UpdateView() + { + OnPropertyChanged(nameof(PageDisplay)); + if (PageNum == 1) + { + BackEnabled = false; + NextEnabled = true; + } + else if (PageNum == MaxPageNum) + { + BackEnabled = true; + NextEnabled = false; + } + else + { + BackEnabled = true; + NextEnabled = true; + } + } + } +} diff --git a/Flow.Launcher/WelcomeWindow.xaml b/Flow.Launcher/WelcomeWindow.xaml index 73f423d0b..e7c483f89 100644 --- a/Flow.Launcher/WelcomeWindow.xaml +++ b/Flow.Launcher/WelcomeWindow.xaml @@ -6,6 +6,7 @@ xmlns:local="clr-namespace:Flow.Launcher" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:ui="http://schemas.modernwpf.com/2019" + xmlns:vm="clr-namespace:Flow.Launcher.ViewModel" Name="FlowWelcomeWindow" Title="{DynamicResource Welcome_Page1_Title}" Width="550" @@ -14,8 +15,10 @@ MinHeight="650" MaxWidth="550" MaxHeight="650" + d:DataContext="{d:DesignInstance Type=vm:WelcomeViewModel}" Activated="OnActivated" Background="{DynamicResource Color00B}" + Closed="Window_Closed" Foreground="{DynamicResource PopupTextColor}" MouseDown="window_MouseDown" WindowStartupLocation="CenterScreen" @@ -41,12 +44,12 @@ Grid.Column="0" Width="16" Height="16" - Margin="10,4,4,4" + Margin="10 4 4 4" RenderOptions.BitmapScalingMode="HighQuality" Source="/Images/app.png" /> + BorderThickness="0 1 0 0"> @@ -109,11 +112,11 @@ VerticalAlignment="Center"> @@ -122,25 +125,26 @@ Grid.Column="0" Width="100" Height="40" - Margin="20,5,0,5" + Margin="20 5 0 5" Click="BtnCancel_OnClick" Content="{DynamicResource Skip}" DockPanel.Dock="Right" FontSize="14" />