临时提交
This commit is contained in:
@@ -55,7 +55,7 @@ public partial class App : System.Windows.Application
|
|||||||
protected override async void OnStartup(StartupEventArgs e)
|
protected override async void OnStartup(StartupEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnStartup(e);
|
base.OnStartup(e);
|
||||||
ShutdownMode = ShutdownMode.OnExplicitShutdown;
|
ShutdownMode = ShutdownMode.OnLastWindowClose;
|
||||||
ThemeHelper.InitializeTheme();
|
ThemeHelper.InitializeTheme();
|
||||||
await Host.StartAsync();
|
await Host.StartAsync();
|
||||||
|
|
||||||
@@ -80,8 +80,8 @@ public partial class App : System.Windows.Application
|
|||||||
NotificationHelper.ShowError("加载数据时发生错误,如果是连接字符串不正确,可以在设置界面更改:{exception.Message}", exception);
|
NotificationHelper.ShowError("加载数据时发生错误,如果是连接字符串不正确,可以在设置界面更改:{exception.Message}", exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow = Host.Services.GetRequiredService<SplashWindow>();
|
var splashWindow = Host.Services.GetRequiredService<SplashWindow>();
|
||||||
MainWindow.Show();
|
splashWindow.Show();
|
||||||
|
|
||||||
// 根据配置启动服务
|
// 根据配置启动服务
|
||||||
// var connectionSettings = DMS.Config.AppSettings.Load();
|
// var connectionSettings = DMS.Config.AppSettings.Load();
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
// 文件: DMS.WPF/Services/NavigationService.cs
|
// 文件: DMS.WPF/Services/NavigationService.cs
|
||||||
|
|
||||||
using DMS.WPF.ViewModels;
|
using DMS.WPF.ViewModels;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
using DMS.ViewModels;
|
using DMS.ViewModels;
|
||||||
|
using DMS.WPF.Views;
|
||||||
|
|
||||||
namespace DMS.WPF.Services;
|
namespace DMS.WPF.Services;
|
||||||
|
|
||||||
@@ -50,23 +53,28 @@ public class NavigationService : INavigationService
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Task ShowMainWindowAsync()
|
public Task ShowMainWindowAsync()
|
||||||
{
|
{
|
||||||
var mainWindow = _serviceProvider.GetRequiredService<MainWindow>();
|
return App.Current.Dispatcher.InvokeAsync(() =>
|
||||||
mainWindow.Show();
|
{
|
||||||
return Task.CompletedTask;
|
var mainView = _serviceProvider.GetRequiredService<MainView>();
|
||||||
|
// 将 MainView 设置为新的主窗口
|
||||||
|
App.Current.MainWindow = mainView;
|
||||||
|
mainView.Show();
|
||||||
|
})
|
||||||
|
.Task;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Type GetViewModelTypeByKey(string key)
|
private Type GetViewModelTypeByKey(string key)
|
||||||
{
|
{
|
||||||
return key switch
|
return key switch
|
||||||
{
|
{
|
||||||
"HomeView" => typeof(HomeViewModel),
|
"HomeView" => typeof(HomeViewModel),
|
||||||
"DevicesView" => typeof(DevicesViewModel),
|
"DevicesView" => typeof(DevicesViewModel),
|
||||||
"DeviceDetailView" => typeof(DeviceDetailViewModel),
|
"DeviceDetailView" => typeof(DeviceDetailViewModel),
|
||||||
"VariableTableView" => typeof(VariableTableViewModel),
|
"VariableTableView" => typeof(VariableTableViewModel),
|
||||||
"MqttsView" => typeof(MqttsViewModel),
|
"MqttsView" => typeof(MqttsViewModel),
|
||||||
"MqttServerDetailView" => typeof(MqttServerDetailViewModel),
|
"MqttServerDetailView" => typeof(MqttServerDetailViewModel),
|
||||||
"SettingView" => typeof(SettingViewModel),
|
"SettingView" => typeof(SettingViewModel),
|
||||||
_ => throw new KeyNotFoundException($"未找到与键 '{key}' 关联的视图模型类型。请检查 NavigationService 的映射配置。")
|
_ => throw new KeyNotFoundException($"未找到与键 '{key}' 关联的视图模型类型。请检查 NavigationService 的映射配置。")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,7 @@ public partial class SplashViewModel : ObservableObject
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 开始执行初始化任务。
|
/// 开始执行初始化任务。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task InitializeAsync()
|
public async Task<bool> InitializeAsync()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -50,12 +50,14 @@ public partial class SplashViewModel : ObservableObject
|
|||||||
// 初始化完成,显示主窗口
|
// 初始化完成,显示主窗口
|
||||||
var navigationService = (INavigationService)_serviceProvider.GetService(typeof(INavigationService));
|
var navigationService = (INavigationService)_serviceProvider.GetService(typeof(INavigationService));
|
||||||
await navigationService.ShowMainWindowAsync();
|
await navigationService.ShowMainWindowAsync();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// 处理初始化过程中的异常
|
// 处理初始化过程中的异常
|
||||||
LoadingMessage = $"初始化失败: {ex.Message}";
|
LoadingMessage = $"初始化失败: {ex.Message}";
|
||||||
// 在此可以记录日志或显示错误对话框
|
// 在此可以记录日志或显示错误对话框
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,11 @@ public partial class SplashWindow : Window
|
|||||||
DataContext = viewModel;
|
DataContext = viewModel;
|
||||||
Loaded += async (s, e) =>
|
Loaded += async (s, e) =>
|
||||||
{
|
{
|
||||||
await viewModel.InitializeAsync();
|
var success = await viewModel.InitializeAsync();
|
||||||
Close();
|
if (success)
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user