Focus input element
This commit is contained in:
@@ -567,7 +567,8 @@
|
||||
Background="{DynamicResource BarelyTransparentBackgroundColor}"
|
||||
HorizontalAlignment="Stretch"
|
||||
IsVisible="{Binding DialogService.ReadInput^, Converter={x:Static ObjectConverters.IsNotNull}}"
|
||||
VerticalAlignment="Stretch">
|
||||
VerticalAlignment="Stretch"
|
||||
x:Name="ReadInputContainer">
|
||||
<Border
|
||||
Background="{DynamicResource ContainerBackgroundBrush}"
|
||||
HorizontalAlignment="Center"
|
||||
@@ -590,12 +591,14 @@
|
||||
<Grid Grid.Column="1">
|
||||
<TextBox
|
||||
IsVisible="{Binding Type, Converter={StaticResource EqualityConverter}, ConverterParameter={x:Static interactions:InputType.Text}}"
|
||||
Tag="InputItem"
|
||||
Text="{Binding Value, Mode=TwoWay}"
|
||||
VerticalAlignment="Top"
|
||||
x:DataType="interactions:TextInputElement" />
|
||||
<TextBox
|
||||
IsVisible="{Binding Type, Converter={StaticResource EqualityConverter}, ConverterParameter={x:Static interactions:InputType.Password}}"
|
||||
PasswordChar="{Binding PasswordChar}"
|
||||
Tag="InputItem"
|
||||
Text="{Binding Value, Mode=TwoWay}"
|
||||
VerticalAlignment="Top"
|
||||
x:DataType="interactions:PasswordInputElement" />
|
||||
@@ -604,6 +607,7 @@
|
||||
IsVisible="{Binding Type, Converter={StaticResource EqualityConverter}, ConverterParameter={x:Static interactions:InputType.Options}}"
|
||||
ItemsSource="{Binding Options}"
|
||||
SelectedItem="{Binding Value}"
|
||||
Tag="InputItem"
|
||||
x:DataType="interactions:IOptionsInputElement" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.VisualTree;
|
||||
using DynamicData;
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
@@ -38,6 +39,8 @@ public partial class MainWindow : Window
|
||||
_modalService.OpenModals.ToCollection().Subscribe(m => _openModals = m);
|
||||
DI.ServiceProvider.GetRequiredService<Services.SystemClipboardService>().TopLevel = GetTopLevel(this);
|
||||
InitializeComponent();
|
||||
|
||||
ReadInputContainer.PropertyChanged += ReadInputContainerOnPropertyChanged;
|
||||
}
|
||||
|
||||
private void OnWindowOpened(object sender, EventArgs e)
|
||||
@@ -110,6 +113,19 @@ public partial class MainWindow : Window
|
||||
}
|
||||
}
|
||||
|
||||
private async void ReadInputContainerOnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.Property.Name == nameof(ReadInputContainer.IsVisible) && ReadInputContainer.IsVisible)
|
||||
{
|
||||
await Task.Delay(100);
|
||||
var inputElement = InputList
|
||||
.GetVisualDescendants()
|
||||
.OfType<Control>()
|
||||
.FirstOrDefault(i => i.Tag as string == "InputItem" && i.IsVisible);
|
||||
inputElement?.Focus();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnWindowClosed(object? sender, EventArgs e)
|
||||
{
|
||||
var vm = ViewModel;
|
||||
|
||||
Reference in New Issue
Block a user