mirror of https://github.com/2dust/v2rayN
Use AutoCompleteBox instead of editable Combobox for desktop
Thanks to https://github.com/irihitech/Ursa.Avaloniamaster
parent
ab73e5acb2
commit
2e962e555d
|
@ -19,6 +19,7 @@
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
<ResourceDictionary.MergedDictionaries>
|
<ResourceDictionary.MergedDictionaries>
|
||||||
<ResourceInclude Source="Assets/GlobalResources.axaml" />
|
<ResourceInclude Source="Assets/GlobalResources.axaml" />
|
||||||
|
<ResourceInclude Source="Controls/AutoCompleteBox.axaml" />
|
||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</Application.Resources>
|
</Application.Resources>
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
<ResourceDictionary
|
||||||
|
xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:controls="clr-namespace:v2rayN.Desktop.Controls">
|
||||||
|
<!-- Add Resources Here -->
|
||||||
|
<ControlTheme x:Key="{x:Type controls:AutoCompleteBox}" TargetType="controls:AutoCompleteBox">
|
||||||
|
<Setter Property="VerticalAlignment" Value="Center" />
|
||||||
|
<Setter Property="MinHeight" Value="{DynamicResource AutoCompleteBoxDefaultHeight}" />
|
||||||
|
<Setter Property="MaxDropDownHeight" Value="{DynamicResource AutoCompleteMaxDropdownHeight}" />
|
||||||
|
<Setter Property="Template">
|
||||||
|
<ControlTemplate TargetType="AutoCompleteBox">
|
||||||
|
<Panel>
|
||||||
|
<TextBox
|
||||||
|
Name="PART_TextBox"
|
||||||
|
MinHeight="{TemplateBinding MinHeight}"
|
||||||
|
VerticalAlignment="Stretch"
|
||||||
|
DataValidationErrors.Errors="{TemplateBinding (DataValidationErrors.Errors)}"
|
||||||
|
InnerLeftContent="{TemplateBinding InnerLeftContent}"
|
||||||
|
InnerRightContent="{TemplateBinding InnerRightContent}"
|
||||||
|
Watermark="{TemplateBinding Watermark}" />
|
||||||
|
<Popup
|
||||||
|
Name="PART_Popup"
|
||||||
|
MaxHeight="{TemplateBinding MaxDropDownHeight}"
|
||||||
|
IsLightDismissEnabled="True"
|
||||||
|
PlacementTarget="{TemplateBinding}">
|
||||||
|
<Border
|
||||||
|
MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}"
|
||||||
|
Margin="{DynamicResource AutoCompleteBoxPopupMargin}"
|
||||||
|
Padding="{DynamicResource AutoCompleteBoxPopupPadding}"
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
Background="{DynamicResource AutoCompleteBoxPopupBackground}"
|
||||||
|
BorderBrush="{DynamicResource AutoCompleteBoxPopupBorderBrush}"
|
||||||
|
BorderThickness="{DynamicResource AutoCompleteBoxPopupBorderThickness}"
|
||||||
|
BoxShadow="{DynamicResource AutoCompleteBoxPopupBoxShadow}"
|
||||||
|
CornerRadius="{DynamicResource AutoCompleteBoxPopupCornerRadius}">
|
||||||
|
<ListBox
|
||||||
|
Name="PART_SelectingItemsControl"
|
||||||
|
Foreground="{TemplateBinding Foreground}"
|
||||||
|
ItemTemplate="{TemplateBinding ItemTemplate}"
|
||||||
|
ScrollViewer.HorizontalScrollBarVisibility="Auto"
|
||||||
|
ScrollViewer.VerticalScrollBarVisibility="Auto" />
|
||||||
|
</Border>
|
||||||
|
</Popup>
|
||||||
|
</Panel>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Setter>
|
||||||
|
</ControlTheme>
|
||||||
|
</ResourceDictionary>
|
|
@ -0,0 +1,38 @@
|
||||||
|
using Avalonia.Input;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
|
||||||
|
namespace v2rayN.Desktop.Controls;
|
||||||
|
|
||||||
|
public class AutoCompleteBox : Avalonia.Controls.AutoCompleteBox
|
||||||
|
{
|
||||||
|
static AutoCompleteBox()
|
||||||
|
{
|
||||||
|
MinimumPrefixLengthProperty.OverrideDefaultValue<AutoCompleteBox>(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AutoCompleteBox()
|
||||||
|
{
|
||||||
|
AddHandler(PointerPressedEvent, OnBoxPointerPressed, RoutingStrategies.Tunnel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnBoxPointerPressed(object? sender, PointerPressedEventArgs e)
|
||||||
|
{
|
||||||
|
if (Equals(sender, this) && e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
|
||||||
|
{
|
||||||
|
SetCurrentValue(IsDropDownOpenProperty, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnGotFocus(GotFocusEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnGotFocus(e);
|
||||||
|
if (IsDropDownOpen)
|
||||||
|
return;
|
||||||
|
SetCurrentValue(IsDropDownOpenProperty, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
SetCurrentValue(SelectedItemProperty, null);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
x:Class="v2rayN.Desktop.Views.OptionSettingWindow"
|
x:Class="v2rayN.Desktop.Views.OptionSettingWindow"
|
||||||
xmlns="https://github.com/avaloniaui"
|
xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:ctrls="clr-namespace:v2rayN.Desktop.Controls"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:resx="clr-namespace:ServiceLib.Resx;assembly=ServiceLib"
|
xmlns:resx="clr-namespace:ServiceLib.Resx;assembly=ServiceLib"
|
||||||
|
@ -219,8 +220,7 @@
|
||||||
Grid.Row="13"
|
Grid.Row="13"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Width="200"
|
Width="200"
|
||||||
Classes="Margin8"
|
Classes="Margin8" />
|
||||||
ToolTip.Tip="Level" />
|
|
||||||
|
|
||||||
<TextBlock
|
<TextBlock
|
||||||
Grid.Row="14"
|
Grid.Row="14"
|
||||||
|
@ -505,13 +505,12 @@
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Classes="Margin8"
|
Classes="Margin8"
|
||||||
Text="{x:Static resx:ResUI.TbSettingsCurrentFontFamily}" />
|
Text="{x:Static resx:ResUI.TbSettingsCurrentFontFamily}" />
|
||||||
<ComboBox
|
<ctrls:AutoCompleteBox
|
||||||
x:Name="cmbcurrentFontFamily"
|
x:Name="cmbcurrentFontFamily"
|
||||||
Grid.Row="15"
|
Grid.Row="15"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Width="200"
|
Width="300"
|
||||||
Classes="Margin8"
|
Classes="Margin8" />
|
||||||
MaxDropDownHeight="1000" />
|
|
||||||
<TextBlock
|
<TextBlock
|
||||||
Grid.Row="15"
|
Grid.Row="15"
|
||||||
Grid.Column="2"
|
Grid.Column="2"
|
||||||
|
@ -552,8 +551,8 @@
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Classes="Margin8"
|
Classes="Margin8"
|
||||||
Text="{x:Static resx:ResUI.TbSettingsSpeedTestUrl}" />
|
Text="{x:Static resx:ResUI.TbSettingsSpeedTestUrl}" />
|
||||||
<ComboBox
|
<ctrls:AutoCompleteBox
|
||||||
x:Name="cmbSpeedTestUrl"
|
Name="cmbSpeedTestUrl"
|
||||||
Grid.Row="18"
|
Grid.Row="18"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Width="300"
|
Width="300"
|
||||||
|
@ -565,7 +564,7 @@
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Classes="Margin8"
|
Classes="Margin8"
|
||||||
Text="{x:Static resx:ResUI.TbSettingsSpeedPingTestUrl}" />
|
Text="{x:Static resx:ResUI.TbSettingsSpeedPingTestUrl}" />
|
||||||
<ComboBox
|
<ctrls:AutoCompleteBox
|
||||||
x:Name="cmbSpeedPingTestUrl"
|
x:Name="cmbSpeedPingTestUrl"
|
||||||
Grid.Row="19"
|
Grid.Row="19"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
|
@ -578,13 +577,12 @@
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Classes="Margin8"
|
Classes="Margin8"
|
||||||
Text="{x:Static resx:ResUI.TbSettingsSubConvert}" />
|
Text="{x:Static resx:ResUI.TbSettingsSubConvert}" />
|
||||||
<ComboBox
|
<ctrls:AutoCompleteBox
|
||||||
x:Name="cmbSubConvertUrl"
|
x:Name="cmbSubConvertUrl"
|
||||||
Grid.Row="20"
|
Grid.Row="20"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Width="300"
|
Width="300"
|
||||||
Classes="Margin8"
|
Classes="Margin8" />
|
||||||
ToolTip.Tip="Convert Url" />
|
|
||||||
|
|
||||||
<TextBlock
|
<TextBlock
|
||||||
Grid.Row="21"
|
Grid.Row="21"
|
||||||
|
@ -596,7 +594,7 @@
|
||||||
x:Name="cmbMainGirdOrientation"
|
x:Name="cmbMainGirdOrientation"
|
||||||
Grid.Row="21"
|
Grid.Row="21"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Width="300"
|
Width="200"
|
||||||
Classes="Margin8" />
|
Classes="Margin8" />
|
||||||
|
|
||||||
<TextBlock
|
<TextBlock
|
||||||
|
@ -687,8 +685,7 @@
|
||||||
<ComboBox
|
<ComboBox
|
||||||
x:Name="cmbsystemProxyAdvancedProtocol"
|
x:Name="cmbsystemProxyAdvancedProtocol"
|
||||||
MinWidth="400"
|
MinWidth="400"
|
||||||
Classes="Margin8"
|
Classes="Margin8" />
|
||||||
ToolTip.Tip="Protocol" />
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
|
|
|
@ -74,18 +74,11 @@ namespace v2rayN.Desktop.Views
|
||||||
{
|
{
|
||||||
cmbSpeedTestTimeout.Items.Add(i * 5);
|
cmbSpeedTestTimeout.Items.Add(i * 5);
|
||||||
}
|
}
|
||||||
Global.SpeedTestUrls.ForEach(it =>
|
|
||||||
{
|
cmbSpeedTestUrl.ItemsSource = Global.SpeedTestUrls;
|
||||||
cmbSpeedTestUrl.Items.Add(it);
|
cmbSpeedPingTestUrl.ItemsSource = Global.SpeedPingTestUrls;
|
||||||
});
|
cmbSubConvertUrl.ItemsSource = Global.SubConvertUrls;
|
||||||
Global.SpeedPingTestUrls.ForEach(it =>
|
|
||||||
{
|
|
||||||
cmbSpeedPingTestUrl.Items.Add(it);
|
|
||||||
});
|
|
||||||
Global.SubConvertUrls.ForEach(it =>
|
|
||||||
{
|
|
||||||
cmbSubConvertUrl.Items.Add(it);
|
|
||||||
});
|
|
||||||
Global.GeoFilesSources.ForEach(it =>
|
Global.GeoFilesSources.ForEach(it =>
|
||||||
{
|
{
|
||||||
cmbGetFilesSourceUrl.Items.Add(it);
|
cmbGetFilesSourceUrl.Items.Add(it);
|
||||||
|
@ -139,12 +132,12 @@ namespace v2rayN.Desktop.Views
|
||||||
this.Bind(ViewModel, vm => vm.Hide2TrayWhenClose, v => v.togHide2TrayWhenClose.IsChecked).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.Hide2TrayWhenClose, v => v.togHide2TrayWhenClose.IsChecked).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.DoubleClick2Activate, v => v.togDoubleClick2Activate.IsChecked).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.DoubleClick2Activate, v => v.togDoubleClick2Activate.IsChecked).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.AutoUpdateInterval, v => v.txtautoUpdateInterval.Text).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.AutoUpdateInterval, v => v.txtautoUpdateInterval.Text).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.CurrentFontFamily, v => v.cmbcurrentFontFamily.SelectedValue).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.CurrentFontFamily, v => v.cmbcurrentFontFamily.Text).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.SpeedTestTimeout, v => v.cmbSpeedTestTimeout.SelectedValue).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.SpeedTestTimeout, v => v.cmbSpeedTestTimeout.SelectedValue).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.SpeedTestUrl, v => v.cmbSpeedTestUrl.SelectedValue).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.SpeedTestUrl, v => v.cmbSpeedTestUrl.Text).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.SpeedPingTestUrl, v => v.cmbSpeedPingTestUrl.SelectedValue).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.SpeedPingTestUrl, v => v.cmbSpeedPingTestUrl.Text).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.MixedConcurrencyCount, v => v.cmbMixedConcurrencyCount.SelectedValue).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.MixedConcurrencyCount, v => v.cmbMixedConcurrencyCount.SelectedValue).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.SubConvertUrl, v => v.cmbSubConvertUrl.SelectedValue).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.SubConvertUrl, v => v.cmbSubConvertUrl.Text).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.MainGirdOrientation, v => v.cmbMainGirdOrientation.SelectedIndex).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.MainGirdOrientation, v => v.cmbMainGirdOrientation.SelectedIndex).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.GeoFileSourceUrl, v => v.cmbGetFilesSourceUrl.SelectedValue).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.GeoFileSourceUrl, v => v.cmbGetFilesSourceUrl.SelectedValue).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.SrsFileSourceUrl, v => v.cmbSrsFilesSourceUrl.SelectedValue).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.SrsFileSourceUrl, v => v.cmbSrsFilesSourceUrl.SelectedValue).DisposeWith(disposables);
|
||||||
|
@ -215,8 +208,9 @@ namespace v2rayN.Desktop.Views
|
||||||
private async Task InitSettingFont()
|
private async Task InitSettingFont()
|
||||||
{
|
{
|
||||||
var lstFonts = await GetFonts();
|
var lstFonts = await GetFonts();
|
||||||
lstFonts.ForEach(it => { cmbcurrentFontFamily.Items.Add(it); });
|
|
||||||
cmbcurrentFontFamily.Items.Add(string.Empty);
|
lstFonts.Add(string.Empty);
|
||||||
|
cmbcurrentFontFamily.ItemsSource = lstFonts;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<List<string>> GetFonts()
|
private async Task<List<string>> GetFonts()
|
||||||
|
|
Loading…
Reference in New Issue