2025-09-02 13:09:00 +08:00
|
|
|
using DMS.Services;
|
|
|
|
|
using DMS.WPF.Helper;
|
2025-09-04 19:59:35 +08:00
|
|
|
using DMS.WPF.Interfaces;
|
2025-09-04 17:29:24 +08:00
|
|
|
using DMS.WPF.Services;
|
2025-07-19 11:11:01 +08:00
|
|
|
using DMS.WPF.ViewModels.Dialogs;
|
2025-10-06 18:17:56 +08:00
|
|
|
using DMS.WPF.ItemViewModel;
|
2025-07-09 13:06:21 +08:00
|
|
|
using iNKORE.UI.WPF.Modern.Controls;
|
2025-09-02 13:09:00 +08:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Threading;
|
2025-09-04 17:29:24 +08:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2025-07-09 13:06:21 +08:00
|
|
|
|
2025-07-26 10:05:43 +08:00
|
|
|
namespace DMS.WPF.Views.Dialogs;
|
2025-07-09 13:06:21 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
2025-08-25 20:16:57 +08:00
|
|
|
/// ImportOpcUaDialog.xaml 的交互逻辑
|
2025-07-09 13:06:21 +08:00
|
|
|
/// </summary>
|
2025-08-25 20:16:57 +08:00
|
|
|
public partial class ImportOpcUaDialog : ContentDialog
|
2025-07-09 13:06:21 +08:00
|
|
|
{
|
2025-09-02 14:37:43 +08:00
|
|
|
private const int ContentAreaMaxWidth = 1300;
|
|
|
|
|
private const int ContentAreaMaxHeight = 900;
|
2025-09-02 13:09:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-07-09 13:06:21 +08:00
|
|
|
|
2025-09-04 17:29:24 +08:00
|
|
|
|
|
|
|
|
|
2025-08-25 21:26:18 +08:00
|
|
|
public ImportOpcUaDialog()
|
2025-07-09 13:06:21 +08:00
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2025-09-02 13:09:00 +08:00
|
|
|
this.Opened += OnOpened;
|
2025-07-09 13:06:21 +08:00
|
|
|
}
|
|
|
|
|
|
2025-09-02 13:09:00 +08:00
|
|
|
private void OnOpened(ContentDialog sender, ContentDialogOpenedEventArgs args)
|
2025-07-09 13:06:21 +08:00
|
|
|
{
|
2025-09-02 13:09:00 +08:00
|
|
|
//修改对话框内容的最大宽度和最大高度
|
|
|
|
|
var backgroundElementBorder = VisualTreeFinder.FindVisualChildByName<Border>(this, "BackgroundElement");
|
|
|
|
|
backgroundElementBorder.MaxWidth = ContentAreaMaxWidth;
|
|
|
|
|
backgroundElementBorder.MaxWidth = ContentAreaMaxHeight;
|
2025-07-09 13:06:21 +08:00
|
|
|
}
|
|
|
|
|
|
2025-09-02 13:09:00 +08:00
|
|
|
private async void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
|
2025-07-09 13:06:21 +08:00
|
|
|
{
|
2025-09-02 13:09:00 +08:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//防止多次调用
|
|
|
|
|
object selectedObj = this.treeView.SelectedItem;
|
|
|
|
|
if (SelectedItemChanged != null)
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.BeginInvoke(DispatcherPriority.Background, SelectedItemChanged, selectedObj);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2025-09-04 19:59:35 +08:00
|
|
|
var notificationService = App.Current.Services.GetRequiredService<INotificationService>();
|
2025-09-04 17:29:24 +08:00
|
|
|
notificationService.ShowError($"选择节点时发生了错误:{ex.Message}");
|
2025-09-02 13:09:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-07-09 13:06:21 +08:00
|
|
|
}
|
|
|
|
|
|
2025-09-02 13:09:00 +08:00
|
|
|
//事件
|
|
|
|
|
public async void SelectedItemChanged(object selectedObj)
|
2025-07-09 13:06:21 +08:00
|
|
|
{
|
2025-10-06 18:17:56 +08:00
|
|
|
if (selectedObj is OpcUaNodeItem selectedNode)
|
2025-09-02 13:09:00 +08:00
|
|
|
{
|
2025-07-09 19:38:36 +08:00
|
|
|
|
2025-09-02 13:09:00 +08:00
|
|
|
if (this.DataContext is ImportOpcUaDialogViewModel viewModel)
|
|
|
|
|
{
|
|
|
|
|
await viewModel.LoadNodeVariables(selectedNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-09 19:38:36 +08:00
|
|
|
|
|
|
|
|
private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs args)
|
|
|
|
|
{
|
2025-09-02 13:09:00 +08:00
|
|
|
// if (args.AddedItems!=null && args.AddedItems.Count>0)
|
|
|
|
|
// {
|
|
|
|
|
// foreach (var item in args.AddedItems)
|
|
|
|
|
// {
|
|
|
|
|
// ViewModel.SelectedVariables.Add((Variable)item);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// }
|
2025-07-09 19:38:36 +08:00
|
|
|
}
|
2025-07-09 13:06:21 +08:00
|
|
|
}
|