Skip to content

Commit

Permalink
[skip ci] WIP: Control focus enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
TheXDS committed Jan 3, 2024
1 parent 74e4ea4 commit ed6d852
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/Platform/Ganymede.Wpf/Controls/Int32TextBox.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using TheXDS.Ganymede.Controls.Primitives;
using System.Windows.Controls.Primitives;
using TheXDS.Ganymede.Controls.Primitives;
using static TheXDS.Ganymede.Helpers.DependencyObjectHelpers;

namespace TheXDS.Ganymede.Controls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private static void OnValueChanged(DependencyObject d, DependencyPropertyChanged
}
}

private TextBoxEx? _tb;
private TextBox? _tb;

/// <summary>
/// Gets or sets the maximum allowed value on this control.
Expand Down Expand Up @@ -180,11 +180,12 @@ public T Value
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_tb = Template.FindName("PART_input", this) as TextBoxEx;
_tb = Template.FindName("PART_input", this) as TextBox;
if (_tb is not null)
{
_tb.Text = Value.ToString();
_tb.TextChanged += Tb_TextChanged;
_tb.GotKeyboardFocus += (_, _) => _tb.SelectAll();
}
WireUp("increase", _Settings.Add);
WireUp("decrease", _Settings.Subtract);
Expand All @@ -209,6 +210,7 @@ private void Tb_TextChanged(object sender, TextChangedEventArgs e)
else
{
_tb.Text = Value.ToString();
_tb.SelectAll();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Path Fill="Black" Data="M 0 0 L 3 3 L 6 0 Z"/>
</RepeatButton>
</UniformGrid>
<controls:TextBoxEx Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
<controls:TextBoxEx TabIndex="1" Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
Expand All @@ -34,7 +34,7 @@
<Path Fill="Black" Data="M 0 0 L 3 3 L 6 0 Z"/>
</RepeatButton>
</UniformGrid>
<controls:TextBoxEx Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
<controls:TextBoxEx TabIndex="1" Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
Expand All @@ -53,14 +53,14 @@
<Path Fill="Black" Data="M 0 0 L 3 3 L 6 0 Z"/>
</RepeatButton>
</UniformGrid>
<controls:TextBoxEx Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
<controls:TextBoxEx TabIndex="1" Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type controls:UInt16TextBox}">
<Setter Property="Template">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:UInt16TextBox}">
<DockPanel>
Expand All @@ -72,13 +72,14 @@
<Path Fill="Black" Data="M 0 0 L 3 3 L 6 0 Z"/>
</RepeatButton>
</UniformGrid>
<controls:TextBoxEx Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
<controls:TextBoxEx TabIndex="1" Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type controls:Int32TextBox}">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:Int32TextBox}">
Expand All @@ -91,7 +92,7 @@
<Path Fill="Black" Data="M 0 0 L 3 3 L 6 0 Z"/>
</RepeatButton>
</UniformGrid>
<controls:TextBoxEx Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
<controls:TextBoxEx IsTabStop="True" Focusable="True" TabIndex="1" Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
Expand All @@ -110,7 +111,7 @@
<Path Fill="Black" Data="M 0 0 L 3 3 L 6 0 Z"/>
</RepeatButton>
</UniformGrid>
<controls:TextBoxEx Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
<controls:TextBoxEx TabIndex="1" Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
Expand All @@ -129,7 +130,7 @@
<Path Fill="Black" Data="M 0 0 L 3 3 L 6 0 Z"/>
</RepeatButton>
</UniformGrid>
<controls:TextBoxEx Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
<controls:TextBoxEx TabIndex="1" Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
Expand All @@ -148,7 +149,7 @@
<Path Fill="Black" Data="M 0 0 L 3 3 L 6 0 Z"/>
</RepeatButton>
</UniformGrid>
<controls:TextBoxEx Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
<controls:TextBoxEx TabIndex="1" Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
Expand All @@ -167,7 +168,7 @@
<Path Fill="Black" Data="M 0 0 L 3 3 L 6 0 Z"/>
</RepeatButton>
</UniformGrid>
<controls:TextBoxEx Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
<controls:TextBoxEx TabIndex="1" Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
Expand All @@ -186,7 +187,7 @@
<Path Fill="Black" Data="M 0 0 L 3 3 L 6 0 Z"/>
</RepeatButton>
</UniformGrid>
<controls:TextBoxEx Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
<controls:TextBoxEx TabIndex="1" Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
Expand All @@ -205,7 +206,7 @@
<Path Fill="Black" Data="M 0 0 L 3 3 L 6 0 Z"/>
</RepeatButton>
</UniformGrid>
<controls:TextBoxEx Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
<controls:TextBoxEx TabIndex="1" Icon="{TemplateBinding Icon}" Label="{TemplateBinding Label}" x:Name="PART_input"/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<vc:BooleanInverter x:Key="binv"/>
<vc:NullToBooleanConverter x:Key="n2vc"/>
<Style TargetType="c:NavigationViewModelHost">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="c:NavigationViewModelHost">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class CredentialDialogTemplateBuilder : IDialogTemplateBuilder<Credential
viewModel.Password = pwd.SecurePassword;
};
usr.SetBinding(TextBox.TextProperty, new Binding(nameof(viewModel.User)));

return new StackPanel() { Children = { usr, pwd } };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using TheXDS.Ganymede.Controls;
using TheXDS.Ganymede.Controls.Primitives;
using TheXDS.Ganymede.Resources.DialogTemplates;
Expand Down Expand Up @@ -48,7 +49,20 @@ static DialogVisualConverter()
public FrameworkElement? Convert(DialogViewModel value, object? parameter, CultureInfo? culture)
{
var builder = Builders.FirstOrDefault(p => p.CanBuild(value));
return builder?.Build(value)!;
var result = builder?.Build(value);
if (result is not null)
{
result.Loaded += DialogContent_Loaded;
}
return result;
}

private void DialogContent_Loaded(object sender, RoutedEventArgs e)
{
FrameworkElement control = (FrameworkElement)sender;
control.Focus();
Keyboard.Focus(control);
control.Loaded -= DialogContent_Loaded;
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Platform/Ganymede.Wpf/Views/Dialogs/DialogView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
</StackPanel>
</ScrollViewer>
<ItemsControl
IsTabStop="False"
HorizontalAlignment="Center"
Margin="5"
Grid.Row="2"
Expand All @@ -95,6 +96,7 @@
SnapsToDevicePixels="True"
Padding="10,5"
Margin="5"
IsDefault="{Binding IsPrimary, Mode=OneWay}"
Content="{Binding Text, Mode=OneWay}"
Command="{Binding Command, Mode=OneWay}"/>
</DataTemplate>
Expand Down

0 comments on commit ed6d852

Please sign in to comment.