ソースを参照

avalonia: Allowed for changing module title
avalonia: Updated versions

Kenric Nugteren 4 週間 前
コミット
f07c01e8d6

+ 5 - 5
PRS.Avalonia/PRS.Avalonia.Android/PRS.Avalonia.Android.csproj

@@ -1,7 +1,7 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
     <PropertyGroup>
         <OutputType>Exe</OutputType>
-        <TargetFramework>net8.0-android</TargetFramework>
+        <TargetFramework>net9.0-android</TargetFramework>
         <SupportedOSPlatformVersion>34</SupportedOSPlatformVersion>
         <TargetPlatformSdkRootOverride>34</TargetPlatformSdkRootOverride>
         <Nullable>enable</Nullable>
@@ -16,14 +16,14 @@
     </PropertyGroup>
     
     <ItemGroup>
-        <PackageReference Include="Avalonia.Android" Version="11.2.2" />
-        <PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.2" />
+        <PackageReference Include="Avalonia.Android" Version="11.3.2" />
+        <PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.2" />
         <PackageReference Include="Xamarin.AndroidX.Core.SplashScreen" Version="1.0.1.14" />
     </ItemGroup>
 
     <ItemGroup>
         <ProjectReference Include="..\..\..\inabox\InABox.Avalonia.Platform.Android\InABox.Avalonia.Platform.Android.csproj" />
-        <ProjectReference Include="..\PRS.Avalonia\PRS.Avalonia.csproj"/>
+        <ProjectReference Include="..\PRS.Avalonia\PRS.Avalonia.csproj" />
     </ItemGroup>
 
     <ItemGroup>

+ 2 - 2
PRS.Avalonia/PRS.Avalonia.Desktop/PRS.Avalonia.Desktop.csproj

@@ -25,8 +25,8 @@
     </PropertyGroup>
 
     <ItemGroup>
-        <PackageReference Include="Avalonia.Desktop" Version="11.2.2" />
-        <PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.2" />
+        <PackageReference Include="Avalonia.Desktop" Version="11.3.2" />
+        <PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.2" />
         <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
     </ItemGroup>
 

+ 4 - 0
PRS.Avalonia/PRS.Avalonia/Components/SelectionView/SelectionViewModel.cs

@@ -75,6 +75,8 @@ public partial class SelectionViewModel : PopupViewModel<object?[]>, IModuleView
 
     private object?[] _selectedItems = [];
 
+    public event Action<string>? OnTitleChanged;
+
     public SelectionViewModel()
     {
         PrimaryMenu.Add(new(Images.tick, Tick_Click));
@@ -173,4 +175,6 @@ public partial class SelectionViewModel : PopupViewModel<object?[]>, IModuleView
             };
         });
     }
+
+    public string GetTitle() => Title;
 }

+ 13 - 5
PRS.Avalonia/PRS.Avalonia/MainViewModel.cs

@@ -1,4 +1,6 @@
-using System.Linq;
+using System;
+using System.Linq;
+using Avalonia.Threading;
 using CommunityToolkit.Mvvm.ComponentModel;
 using InABox.Avalonia;
 using InABox.Avalonia.Router;
@@ -30,9 +32,15 @@ public partial class MainViewModel : ViewModelBase
                 Content.Deactivate();
             IsTransitioning = true;
             Content = viewModel;
-            Title = viewModel is IModuleViewModel module
-                ? module.Title
-                : Repositories.MaybeMe?.Name ?? "PRS Avalonia";
+            if(viewModel is IModuleViewModel module)
+            {
+                Title = module.GetTitle();
+                module.OnTitleChanged += title => Dispatcher.UIThread.InvokeAsync(() => Title = title);
+            }
+            else
+            {
+                Title = Repositories.MaybeMe?.Name ?? "PRS Avalonia";
+            }
             PrimaryMenu = viewModel.PrimaryMenu;
             SecondaryMenu = viewModel.SecondaryMenu;
             BackButtonVisible = viewModel.BackButtonVisible;
@@ -53,7 +61,7 @@ public partial class MainViewModel : ViewModelBase
         PropertyChanged += MainViewModel_PropertyChanged;
 
         // change to HomeView 
-        Navigation.Reset<TestViewModel>();
+        Navigation.Reset<LoginViewModel>();
     }
 
     public override bool OnBackButtonPressed()

+ 20 - 0
PRS.Avalonia/PRS.Avalonia/Modules/ModuleViewModel.cs

@@ -1,13 +1,33 @@
 using CommunityToolkit.Mvvm.ComponentModel;
+using System;
 
 namespace PRS.Avalonia.Modules;
 
 public interface IModuleViewModel
 {
     string Title { get; }
+
+    event Action<string>? OnTitleChanged;
+
+    string GetTitle();
 }
 
 public abstract class ModuleViewModel : ViewModelBase, IModuleViewModel
 {
     public abstract string Title { get; }
+
+    public event Action<string>? OnTitleChanged;
+
+
+    private string? _title;
+    public void UpdateTitle(string title)
+    {
+        _title = title;
+        OnTitleChanged?.Invoke(title);
+    }
+
+    public string GetTitle()
+    {
+        return _title ?? Title;
+    }
 }

+ 6 - 2
PRS.Avalonia/PRS.Avalonia/PRS.Avalonia.csproj

@@ -1,6 +1,6 @@
 <Project Sdk="Microsoft.NET.Sdk">
     <PropertyGroup>
-        <TargetFrameworks>net8.0;net9.0</TargetFrameworks>
+        <TargetFrameworks>net9.0</TargetFrameworks>
         <Nullable>enable</Nullable>
         <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
         <Configurations>Debug;Release;DebugDev;Publish</Configurations>
@@ -304,6 +304,10 @@
 
     <ItemGroup>
         
+        <PackageReference Include="Avalonia.Controls.DataGrid" Version="11.3.2" />
+        
+        <PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.2" />
+        
         <PackageReference Include="Avalonia.Skia" Version="11.3.2" />
         <PackageReference Include="Avalonia.Controls.ColorPicker" Version="11.3.2" />
         <PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.2" />
@@ -313,7 +317,7 @@
         <PackageReference Include="Microsoft.Maui.Essentials" Version="9.0.90" />
         
         <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
-		<PackageReference Condition="'$(Configuration)' == 'DebugDev'" Include="Avalonia.Diagnostics" Version="11.2.2"/>
+		<PackageReference Condition="'$(Configuration)' == 'DebugDev'" Include="Avalonia.Diagnostics" Version="11.3.2" />
 		<PackageReference Include="ReactiveUI" Version="20.4.1" />
 		<PackageReference Include="Svg.Controls.Skia.Avalonia" Version="11.3.0.3" />