mirror of https://github.com/2dust/v2rayN
Autofit Column Width
parent
c7297dba7e
commit
12ebad436a
|
@ -0,0 +1,12 @@
|
|||
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace v2rayN.Mode
|
||||
{
|
||||
public enum EViewAction
|
||||
{
|
||||
AdjustMainLvColWidth,
|
||||
ProfilesFocus
|
||||
|
||||
}
|
||||
}
|
|
@ -38,7 +38,7 @@ namespace v2rayN.ViewModels
|
|||
private NoticeHandler? _noticeHandler;
|
||||
private readonly PaletteHelper _paletteHelper = new();
|
||||
private Dictionary<string, bool> _dicHeaderSort = new();
|
||||
private Action<string> _updateView;
|
||||
private Action<EViewAction> _updateView;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -201,7 +201,7 @@ namespace v2rayN.ViewModels
|
|||
|
||||
#region Init
|
||||
|
||||
public MainWindowViewModel(ISnackbarMessageQueue snackbarMessageQueue, Action<string> updateView)
|
||||
public MainWindowViewModel(ISnackbarMessageQueue snackbarMessageQueue, Action<EViewAction> 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)
|
||||
|
|
|
@ -378,6 +378,14 @@
|
|||
Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}">
|
||||
<materialDesign:PackIcon VerticalAlignment="Center" Kind="Plus" />
|
||||
</Button>
|
||||
<Button
|
||||
x:Name="btnAutofitColumnWidth"
|
||||
Width="30"
|
||||
Height="30"
|
||||
Margin="4,0"
|
||||
Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}">
|
||||
<materialDesign:PackIcon VerticalAlignment="Center" Kind="ArrowSplitVertical" />
|
||||
</Button>
|
||||
<TextBox
|
||||
x:Name="txtServerFilter"
|
||||
Width="200"
|
||||
|
@ -484,7 +492,6 @@
|
|||
CanUserSortColumns="False"
|
||||
EnableRowVirtualization="True"
|
||||
Focusable="True"
|
||||
FrozenColumnCount="1"
|
||||
GridLinesVisibility="All"
|
||||
HeadersVisibility="All"
|
||||
IsReadOnly="True"
|
||||
|
@ -615,16 +622,16 @@
|
|||
<Style BasedOn="{StaticResource MaterialDesignDataGridColumnHeader}" TargetType="DataGridColumnHeader">
|
||||
<EventSetter Event="Click" Handler="LstProfiles_ColumnHeader_Click" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="DataGridCell" BasedOn="{StaticResource MaterialDesignDataGridCell}">
|
||||
|
||||
<Style BasedOn="{StaticResource MaterialDesignDataGridCell}" TargetType="DataGridCell">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding isActive}" Value="True">
|
||||
<Setter Property="Background" Value="{DynamicResource PrimaryHueLightBrush}"/>
|
||||
<Setter Property="Foreground" Value="Black"></Setter>
|
||||
<Setter Property="Background" Value="{DynamicResource PrimaryHueLightBrush}" />
|
||||
<Setter Property="Foreground" Value="Black" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
|
||||
</DataGrid.Resources>
|
||||
<DataGrid.Columns>
|
||||
|
||||
|
|
|
@ -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 ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue