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