全局组件通讯研究

This commit is contained in:
2025-05-04 10:22:38 +08:00
parent d9983b0a99
commit 7635174516
5 changed files with 43 additions and 8 deletions

View File

@@ -40,6 +40,8 @@ namespace linesider_screen_bankend.Modules.ModuleName
containerRegistry.RegisterSingleton<IMessageService, MessageService>();
containerRegistry.RegisterSingleton<ILogService, LogService>();
containerRegistry.RegisterSingleton<IPortService, PortService>();
containerRegistry.RegisterSingleton<IPrintService, PrintService>();
containerRegistry.RegisterSingleton<IMqttService, MqttService>();
Debug.WriteLine($"Service方法注册成功");
}

View File

@@ -1,7 +1,11 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using Dm;
using linesider_screen_bankend.Core.Mvvm;
using linesider_screen_bankend.Services.Interfaces;
using Prism.Commands;
using Prism.Ioc;
using Prism.Regions;
@@ -9,6 +13,7 @@ namespace linesider_screen_bankend.Modules.ModuleName.ViewModels
{
public class SettingsPageViewModel : RegionViewModelBase
{
private List<string> _portList;
public List<string> PortList
{
@@ -56,15 +61,20 @@ namespace linesider_screen_bankend.Modules.ModuleName.ViewModels
set { SetProperty(ref _mqtttTopic, value); }
}
// 按钮事件
private DelegateCommand _testCommand;
public DelegateCommand TestCommand =>
_testCommand ?? (_testCommand = new DelegateCommand(ExecuteTestCommand));
IPortService _portService;
public SettingsPageViewModel(IRegionManager regionManager, IPortService portService) :
private IPortService _portService;
private IPrintService _printService;
public SettingsPageViewModel(IRegionManager regionManager, IPortService portService, IPrintService printService) :
base(regionManager)
{
Debug.WriteLine("viewModel方法启动测试1");
_portService = portService;
_printService = printService;
Message = "139.224.232.211";
InitializePortAndBaudLists();
}
@@ -74,10 +84,15 @@ namespace linesider_screen_bankend.Modules.ModuleName.ViewModels
PortList = _portService.GetPortOptions();
BaudList = _portService.GetBaudOptions();
}
public override void OnNavigatedTo(NavigationContext navigationContext)
{
//do something
}
// 按钮事件
void ExecuteTestCommand()
{
_printService.DoPrint("测试地址");
}
}
}

View File

@@ -85,7 +85,7 @@
</StackPanel>
</StackPanel>
<StackPanel Margin="0,0,0,20" Orientation="Horizontal">
<Button Margin="0,0,20,0" Content="连接测试" Background="Gray" Foreground="White" Style="{StaticResource MaterialDesignRaisedButton}"/>
<Button Margin="0,0,20,0" Command="{Binding TestCommand}" Content="连接测试" Background="Gray" Foreground="White" Style="{StaticResource MaterialDesignRaisedButton}"/>
<Button Content="保存" Background="Green" Foreground="White" Style="{StaticResource MaterialDesignRaisedButton}"/>
</StackPanel>
</StackPanel>

View File

@@ -0,0 +1,16 @@
using linesider_screen_bankend.Services.Interfaces;
namespace linesider_screen_bankend.Services
{
public class MqttService : IMqttService
{
public void StartMqtt()
{
throw new System.NotImplementedException();
}
public void EndMqtt()
{
throw new System.NotImplementedException();
}
}
}

View File

@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using linesider_screen_bankend.Services.Interfaces;
namespace linesider_screen_bankend.Services
{
@@ -6,7 +8,7 @@ namespace linesider_screen_bankend.Services
{
public void DoPrint(string labelPath)
{
throw new System.NotImplementedException();
Debug.WriteLine($"地址:{labelPath}");
}
}
}