From cb6122f87299a96f2f57575ef9d37d13cd7c28e9 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Mon, 16 Jun 2025 10:48:35 +0800 Subject: [PATCH] First scroll horizontally to the initial position to avoid the control crash bug https://github.com/2dust/v2rayN/issues/7387 --- .../Views/ProfilesView.axaml.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs index 9bcdb85a..f72c1f51 100644 --- a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs @@ -215,7 +215,7 @@ public partial class ProfilesView : ReactiveUserControl await ViewModel.RefreshServersBiz(); } - if (lstProfiles.SelectedIndex > 0) + if (lstProfiles.SelectedIndex >= 0) { lstProfiles.ScrollIntoView(lstProfiles.SelectedItem, null); } @@ -347,6 +347,24 @@ public partial class ProfilesView : ReactiveUserControl { try { + //First scroll horizontally to the initial position to avoid the control crash bug + if (lstProfiles.SelectedIndex >= 0) + { + lstProfiles.ScrollIntoView(lstProfiles.SelectedItem, lstProfiles.Columns[0]); + } + else + { + var model = lstProfiles.ItemsSource.Cast(); + if (model.Any()) + { + lstProfiles.ScrollIntoView(model.First(), lstProfiles.Columns[0]); + } + else + { + return; + } + } + foreach (var it in lstProfiles.Columns) { it.Width = new DataGridLength(1, DataGridLengthUnitType.Auto);