From 14144e865c16c77073c5ec757fe8443bc2423930 Mon Sep 17 00:00:00 2001 From: "David P.G" Date: Tue, 2 Sep 2025 15:02:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=AF=B9=E8=AF=9D=E6=A1=86?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dialogs/ImportOpcUaDialogViewModel.cs | 35 +++++++++---------- DMS.WPF/Views/Dialogs/ImportOpcUaDialog.xaml | 12 +++++-- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/DMS.WPF/ViewModels/Dialogs/ImportOpcUaDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/ImportOpcUaDialogViewModel.cs index 0370a67..da7a962 100644 --- a/DMS.WPF/ViewModels/Dialogs/ImportOpcUaDialogViewModel.cs +++ b/DMS.WPF/ViewModels/Dialogs/ImportOpcUaDialogViewModel.cs @@ -10,6 +10,7 @@ using DMS.Infrastructure.Models; using DMS.WPF.ViewModels.Items; using Opc.Ua; using Opc.Ua.Client; +using System.Collections; using System.Collections.ObjectModel; namespace DMS.WPF.ViewModels.Dialogs; @@ -23,10 +24,10 @@ public partial class ImportOpcUaDialogViewModel : DialogViewModelBase _selectedNodeVariables; - - public List SelectedVariables { get; set; } = new List(); + private ObservableCollection _opcUaNodeVariables=new ObservableCollection(); + [ObservableProperty] + private IList _selectedVariables = new ArrayList(); [ObservableProperty] private bool _selectAllVariables; @@ -47,7 +48,6 @@ public partial class ImportOpcUaDialogViewModel : DialogViewModelBase(); this._opcUaService = opcUaService; this._mapper = mapper; RootOpcUaNode = new OpcUaNodeItemViewModel() { DisplayName = "根节点", NodeId = Objects.ObjectsFolder, IsExpanded = true }; @@ -90,10 +90,20 @@ public partial class ImportOpcUaDialogViewModel : DialogViewModelBase().ToList()); + } + [RelayCommand] private async void PrimaryButton() { await _opcUaService.DisconnectAsync(); + + Close(OpcUaNodeVariables.ToList()); } [RelayCommand] @@ -122,20 +132,7 @@ public partial class ImportOpcUaDialogViewModel : DialogViewModelBase(children); if (children.NodeClass == NodeClass.Variable) { - SelectedNodeVariables.Add(new VariableItemViewModel + OpcUaNodeVariables.Add(new VariableItemViewModel { Name = children.DisplayName, // 修正:使用子节点的显示名称 OpcUaNodeId = children.NodeId.ToString(), diff --git a/DMS.WPF/Views/Dialogs/ImportOpcUaDialog.xaml b/DMS.WPF/Views/Dialogs/ImportOpcUaDialog.xaml index 84c11c4..aa499a6 100644 --- a/DMS.WPF/Views/Dialogs/ImportOpcUaDialog.xaml +++ b/DMS.WPF/Views/Dialogs/ImportOpcUaDialog.xaml @@ -4,6 +4,8 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="http://schemas.inkore.net/lib/ui/wpf/modern" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:helper="clr-namespace:DMS.WPF.Helper" + xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="clr-namespace:DMS.WPF.ViewModels.Dialogs" Title="从OPC UA服务器导入变量" @@ -11,7 +13,9 @@ CloseButtonCommand="{Binding CloseButtonCommand}" CloseButtonText="取消" PrimaryButtonCommand="{Binding PrimaryButtonCommand}" - PrimaryButtonText="导入" + PrimaryButtonText="导入全部" + SecondaryButtonCommand="{Binding SecondaryButtonCommand}" + SecondaryButtonText="导入选择" mc:Ignorable="d"> @@ -88,8 +92,10 @@ Grid.Column="1" AutoGenerateColumns="False" IsReadOnly="True" - ItemsSource="{Binding SelectedNodeVariables}" - SelectionChanged="Selector_OnSelectionChanged"> + ItemsSource="{Binding OpcUaNodeVariables}"> + + +