From 73c2a203de55f5273caa14d1038b68f642be19dd Mon Sep 17 00:00:00 2001 From: DHR60 Date: Thu, 11 Sep 2025 14:36:37 +0800 Subject: [PATCH] Fix --- .../ViewModels/AddGroupServerViewModel.cs | 20 +++++++++++++------ .../Views/AddGroupServerWindow.axaml.cs | 10 ++++++++++ v2rayN/v2rayN/Views/AddGroupServerWindow.xaml | 1 - .../v2rayN/Views/AddGroupServerWindow.xaml.cs | 10 ++++++++++ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/v2rayN/ServiceLib/ViewModels/AddGroupServerViewModel.cs b/v2rayN/ServiceLib/ViewModels/AddGroupServerViewModel.cs index 2a7f13f3..fe5713f9 100644 --- a/v2rayN/ServiceLib/ViewModels/AddGroupServerViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/AddGroupServerViewModel.cs @@ -1,3 +1,4 @@ +using System.Data; using System.Reactive; using DynamicData.Binding; using ReactiveUI; @@ -105,7 +106,13 @@ public class AddGroupServerViewModel : MyReactiveObject NoticeManager.Instance.Enqueue(ResUI.PleaseSelectServer); return; } - ChildItemsObs.Remove(SelectedChild); + foreach (var it in SelectedChildren ?? [SelectedChild]) + { + if (it != null) + { + ChildItemsObs.Remove(it); + } + } await Task.CompletedTask; } @@ -121,6 +128,7 @@ public class AddGroupServerViewModel : MyReactiveObject { return; } + var selectedChild = JsonUtils.DeepCopy(SelectedChild); switch (eMove) { case EMove.Top: @@ -129,7 +137,7 @@ public class AddGroupServerViewModel : MyReactiveObject return; } ChildItemsObs.RemoveAt(index); - ChildItemsObs.Insert(0, SelectedChild); + ChildItemsObs.Insert(0, selectedChild); break; case EMove.Up: if (index == 0) @@ -137,7 +145,7 @@ public class AddGroupServerViewModel : MyReactiveObject return; } ChildItemsObs.RemoveAt(index); - ChildItemsObs.Insert(index - 1, SelectedChild); + ChildItemsObs.Insert(index - 1, selectedChild); break; case EMove.Down: if (index == ChildItemsObs.Count - 1) @@ -145,7 +153,7 @@ public class AddGroupServerViewModel : MyReactiveObject return; } ChildItemsObs.RemoveAt(index); - ChildItemsObs.Insert(index + 1, SelectedChild); + ChildItemsObs.Insert(index + 1, selectedChild); break; case EMove.Bottom: if (index == ChildItemsObs.Count - 1) @@ -153,7 +161,7 @@ public class AddGroupServerViewModel : MyReactiveObject return; } ChildItemsObs.RemoveAt(index); - ChildItemsObs.Add(SelectedChild); + ChildItemsObs.Add(selectedChild); break; default: break; @@ -183,7 +191,7 @@ public class AddGroupServerViewModel : MyReactiveObject var childIndexIds = new List(); foreach (var item in ChildItemsObs) { - if (item.IndexId.IsNotEmpty()) + if (!item.IndexId.IsNullOrEmpty()) { childIndexIds.Add(item.IndexId); } diff --git a/v2rayN/v2rayN.Desktop/Views/AddGroupServerWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/AddGroupServerWindow.axaml.cs index 631f201c..7e375235 100644 --- a/v2rayN/v2rayN.Desktop/Views/AddGroupServerWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/AddGroupServerWindow.axaml.cs @@ -21,6 +21,7 @@ public partial class AddGroupServerWindow : WindowBase this.Loaded += Window_Loaded; btnCancel.Click += (s, e) => this.Close(); + lstChild.SelectionChanged += LstChild_SelectionChanged; ViewModel = new AddGroupServerViewModel(profileItem, UpdateViewHandler); @@ -145,4 +146,13 @@ public partial class AddGroupServerWindow : WindowBase ViewModel?.ChildItemsObs.AddRange(profiles); } } + + private void LstChild_SelectionChanged(object? sender, SelectionChangedEventArgs e) + { + if (ViewModel != null) + { + ViewModel.SelectedChildren = lstChild.SelectedItems.Cast().ToList(); + } + } + } diff --git a/v2rayN/v2rayN/Views/AddGroupServerWindow.xaml b/v2rayN/v2rayN/Views/AddGroupServerWindow.xaml index 56fb7211..b1867be8 100644 --- a/v2rayN/v2rayN/Views/AddGroupServerWindow.xaml +++ b/v2rayN/v2rayN/Views/AddGroupServerWindow.xaml @@ -73,7 +73,6 @@ Style="{StaticResource ModuleTitle}" Text="{x:Static resx:ResUI.menuServers}" /> - vm.PolicyGroupType, v => v.cmbPolicyGroupType.Text).DisposeWith(disposables); this.OneWayBind(ViewModel, vm => vm.ChildItemsObs, v => v.lstChild.ItemsSource).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.SelectedChild, v => v.lstChild.SelectedItem).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.RemoveCmd, v => v.menuRemoveChildServer).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.MoveTopCmd, v => v.menuMoveTop).DisposeWith(disposables); @@ -120,4 +122,12 @@ public partial class AddGroupServerWindow ViewModel?.ChildItemsObs.AddRange(profiles); } } + + private void LstChild_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) + { + if (ViewModel != null) + { + ViewModel.SelectedChildren = lstChild.SelectedItems.Cast().ToList(); + } + } }