diff --git a/v2rayN/v2rayN/Mode/EViewAction.cs b/v2rayN/v2rayN/Mode/EViewAction.cs new file mode 100644 index 00000000..39da1cf3 --- /dev/null +++ b/v2rayN/v2rayN/Mode/EViewAction.cs @@ -0,0 +1,12 @@ + +using System.ComponentModel; + +namespace v2rayN.Mode +{ + public enum EViewAction + { + AdjustMainLvColWidth, + ProfilesFocus + + } +} diff --git a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs index 5ef5ecd4..8afdbfa9 100644 --- a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs @@ -38,7 +38,7 @@ namespace v2rayN.ViewModels private NoticeHandler? _noticeHandler; private readonly PaletteHelper _paletteHelper = new(); private Dictionary _dicHeaderSort = new(); - private Action _updateView; + private Action _updateView; #endregion @@ -201,7 +201,7 @@ namespace v2rayN.ViewModels #region Init - public MainWindowViewModel(ISnackbarMessageQueue snackbarMessageQueue, Action updateView) + public MainWindowViewModel(ISnackbarMessageQueue snackbarMessageQueue, Action updateView) { _updateView = updateView; ThreadPool.RegisterWaitForSingleObject(App.ProgramStarted, OnProgramStarted, null, -1, false); @@ -549,7 +549,7 @@ namespace v2rayN.ViewModels } if (_config.uiItem.enableAutoAdjustMainLvColWidth) { - _updateView("AdjustMainLvColWidth"); + _updateView(EViewAction.AdjustMainLvColWidth); } } } @@ -702,7 +702,7 @@ namespace v2rayN.ViewModels RefreshServers(); - _updateView("ProfilesFocus"); + _updateView(EViewAction.ProfilesFocus); } private void ServerFilterChanged(bool c) diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml b/v2rayN/v2rayN/Views/MainWindow.xaml index b19292ab..3d3672ef 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml +++ b/v2rayN/v2rayN/Views/MainWindow.xaml @@ -378,6 +378,14 @@ Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}"> + - - - + diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index 3f0fb6e1..ab0d1460 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -31,6 +31,7 @@ namespace v2rayN.Views App.Current.SessionEnding += Current_SessionEnding; this.Closing += MainWindow_Closing; this.PreviewKeyDown += MainWindow_PreviewKeyDown; + btnAutofitColumnWidth.Click += BtnAutofitColumnWidth_Click; lstProfiles.PreviewKeyDown += LstProfiles_PreviewKeyDown; lstProfiles.SelectionChanged += lstProfiles_SelectionChanged; lstProfiles.LoadingRow += LstProfiles_LoadingRow; @@ -202,23 +203,20 @@ namespace v2rayN.Views { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; } - } + } #region Event - private void UpdateViewHandler(string action) + private void UpdateViewHandler(EViewAction action) { - if (action == "AdjustMainLvColWidth") + if (action == EViewAction.AdjustMainLvColWidth) { Application.Current.Dispatcher.Invoke(() => { - foreach (var it in lstProfiles.Columns) - { - it.Width = new DataGridLength(1, DataGridLengthUnitType.Auto); - } + AutofitColumnWidth(); }); } - else if (action == "ProfilesFocus") + else if (action == EViewAction.ProfilesFocus) { lstProfiles.Focus(); } @@ -255,7 +253,7 @@ namespace v2rayN.Views // lstProfiles.Focus(); //} - e.Row.Header = e.Row.GetIndex() + 1; + e.Row.Header = e.Row.GetIndex() + 1; } private void LstProfiles_MouseDoubleClick(object sender, MouseButtonEventArgs e) @@ -277,17 +275,7 @@ namespace v2rayN.Views { return; } - - if (colHeader.Column.GetType().Name != typeof(MyDGTextColumn).Name) - { - foreach (var it in lstProfiles.Columns) - { - //it.MinWidth = it.ActualWidth; - it.Width = new DataGridLength(1, DataGridLengthUnitType.Auto); - } - return; - } - + var colName = ((MyDGTextColumn)colHeader.Column).ExName; ViewModel?.SortServer(colName); } @@ -408,6 +396,18 @@ namespace v2rayN.Views { Utils.ProcessStart(Utils.GetBinPath("EnableLoopback.exe")); } + + private void BtnAutofitColumnWidth_Click(object sender, RoutedEventArgs e) + { + AutofitColumnWidth(); + } + private void AutofitColumnWidth() + { + foreach (var it in lstProfiles.Columns) + { + it.Width = new DataGridLength(1, DataGridLengthUnitType.Auto); + } + } #endregion #region UI @@ -452,7 +452,7 @@ namespace v2rayN.Views else { item2.Width = item.Width; - item2.DisplayIndex = i + 1; + item2.DisplayIndex = i ; } } }