feat: add DialogFocusHint attached property.
This commit is contained in:
@@ -17,7 +17,10 @@
|
|||||||
<GradientStop Offset="0.9" Color="{DynamicResource SemiLightBlue1Color}" />
|
<GradientStop Offset="0.9" Color="{DynamicResource SemiLightBlue1Color}" />
|
||||||
</LinearGradientBrush>
|
</LinearGradientBrush>
|
||||||
</UserControl.Background>
|
</UserControl.Background>
|
||||||
<Grid Margin="24" RowDefinitions="Auto, *, Auto" MinWidth="400">
|
<Grid
|
||||||
|
MinWidth="400"
|
||||||
|
Margin="24"
|
||||||
|
RowDefinitions="Auto, *, Auto">
|
||||||
<TextBlock
|
<TextBlock
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Margin="8"
|
Margin="8"
|
||||||
@@ -45,7 +48,10 @@
|
|||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Margin="32,8,0,8"
|
Margin="32,8,0,8"
|
||||||
Label="Owner">
|
Label="Owner">
|
||||||
<TextBox u:FormItem.Label="Owner" Text="{Binding Owner}" />
|
<TextBox
|
||||||
|
u:FocusHelper.DialogFocusHint="True"
|
||||||
|
u:FormItem.Label="Owner"
|
||||||
|
Text="{Binding Owner}" />
|
||||||
</u:FormItem>
|
</u:FormItem>
|
||||||
<u:FormItem
|
<u:FormItem
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
@@ -69,9 +75,20 @@
|
|||||||
HorizontalAlignment="Right"
|
HorizontalAlignment="Right"
|
||||||
Orientation="Horizontal"
|
Orientation="Horizontal"
|
||||||
Spacing="8">
|
Spacing="8">
|
||||||
<Button Command="{Binding DialogCommand}" Content="Dialog" Theme="{DynamicResource SolidButton}" />
|
<Button
|
||||||
<Button Command="{Binding OKCommand}" Content="OK" Theme="{DynamicResource SolidButton}" Classes="Tertiary"/>
|
Command="{Binding DialogCommand}"
|
||||||
<Button Command="{Binding CancelCommand}" Content="Cancel" Theme="{DynamicResource SolidButton}" Classes="Tertiary"/>
|
Content="Dialog"
|
||||||
|
Theme="{DynamicResource SolidButton}" />
|
||||||
|
<Button
|
||||||
|
Classes="Tertiary"
|
||||||
|
Command="{Binding OKCommand}"
|
||||||
|
Content="OK"
|
||||||
|
Theme="{DynamicResource SolidButton}" />
|
||||||
|
<Button
|
||||||
|
Classes="Tertiary"
|
||||||
|
Command="{Binding CancelCommand}"
|
||||||
|
Content="Cancel"
|
||||||
|
Theme="{DynamicResource SolidButton}" />
|
||||||
<ComboBox>
|
<ComboBox>
|
||||||
<ComboBoxItem>A</ComboBoxItem>
|
<ComboBoxItem>A</ComboBoxItem>
|
||||||
<ComboBoxItem>B</ComboBoxItem>
|
<ComboBoxItem>B</ComboBoxItem>
|
||||||
@@ -79,5 +96,5 @@
|
|||||||
</ComboBox>
|
</ComboBox>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -3,4 +3,5 @@ using Avalonia.Metadata;
|
|||||||
[assembly:XmlnsPrefix("https://irihi.tech/ursa", "u")]
|
[assembly:XmlnsPrefix("https://irihi.tech/ursa", "u")]
|
||||||
[assembly:XmlnsDefinition("https://irihi.tech/ursa", "Ursa")]
|
[assembly:XmlnsDefinition("https://irihi.tech/ursa", "Ursa")]
|
||||||
[assembly:XmlnsDefinition("https://irihi.tech/ursa", "Ursa.Controls")]
|
[assembly:XmlnsDefinition("https://irihi.tech/ursa", "Ursa.Controls")]
|
||||||
[assembly:XmlnsDefinition("https://irihi.tech/ursa", "Ursa.Controls.Shapes")]
|
[assembly:XmlnsDefinition("https://irihi.tech/ursa", "Ursa.Controls.Shapes")]
|
||||||
|
[assembly:XmlnsDefinition("https://irihi.tech/ursa", "Ursa.Helpers")]
|
||||||
@@ -4,6 +4,7 @@ using Avalonia.VisualTree;
|
|||||||
using Irihi.Avalonia.Shared.Helpers;
|
using Irihi.Avalonia.Shared.Helpers;
|
||||||
using Irihi.Avalonia.Shared.Shapes;
|
using Irihi.Avalonia.Shared.Shapes;
|
||||||
using Ursa.Controls.OverlayShared;
|
using Ursa.Controls.OverlayShared;
|
||||||
|
using Ursa.Helpers;
|
||||||
|
|
||||||
namespace Ursa.Controls;
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
@@ -113,12 +114,17 @@ public partial class OverlayDialogHost
|
|||||||
control.AddHandler(DialogControlBase.LayerChangedEvent, OnDialogLayerChanged);
|
control.AddHandler(DialogControlBase.LayerChangedEvent, OnDialogLayerChanged);
|
||||||
if (!IsAnimationDisabled) MaskAppearAnimation.RunAsync(mask);
|
if (!IsAnimationDisabled) MaskAppearAnimation.RunAsync(mask);
|
||||||
|
|
||||||
var element = control.GetVisualDescendants().OfType<InputElement>().FirstOrDefault(a => a.Focusable);
|
var element = control.GetVisualDescendants().OfType<InputElement>()
|
||||||
|
.FirstOrDefault(FocusHelper.GetDialogFocusHint);
|
||||||
|
if (element is null)
|
||||||
|
{
|
||||||
|
element = control.GetVisualDescendants().OfType<InputElement>().FirstOrDefault(a => a.Focusable);
|
||||||
|
}
|
||||||
element?.Focus();
|
element?.Focus();
|
||||||
_modalCount++;
|
_modalCount++;
|
||||||
IsInModalStatus = _modalCount > 0;
|
IsInModalStatus = _modalCount > 0;
|
||||||
control.IsClosed = false;
|
control.IsClosed = false;
|
||||||
control.Focus();
|
// control.Focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle dialog layer change event
|
// Handle dialog layer change event
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using Irihi.Avalonia.Shared.Shapes;
|
|||||||
using Ursa.Common;
|
using Ursa.Common;
|
||||||
using Ursa.Controls.OverlayShared;
|
using Ursa.Controls.OverlayShared;
|
||||||
using Ursa.EventArgs;
|
using Ursa.EventArgs;
|
||||||
|
using Ursa.Helpers;
|
||||||
|
|
||||||
namespace Ursa.Controls;
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
@@ -69,7 +70,13 @@ public partial class OverlayDialogHost
|
|||||||
{
|
{
|
||||||
await Task.WhenAll(animation.RunAsync(control), MaskAppearAnimation.RunAsync(mask));
|
await Task.WhenAll(animation.RunAsync(control), MaskAppearAnimation.RunAsync(mask));
|
||||||
}
|
}
|
||||||
var element = control.GetVisualDescendants().OfType<InputElement>().FirstOrDefault(a => a.Focusable);
|
|
||||||
|
var element = control.GetVisualDescendants().OfType<InputElement>()
|
||||||
|
.FirstOrDefault(FocusHelper.GetDialogFocusHint);
|
||||||
|
if (element is null)
|
||||||
|
{
|
||||||
|
element = control.GetVisualDescendants().OfType<InputElement>().FirstOrDefault(a => a.Focusable);
|
||||||
|
}
|
||||||
element?.Focus();
|
element?.Focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
src/Ursa/Helpers/FocusHelper.cs
Normal file
13
src/Ursa/Helpers/FocusHelper.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Input;
|
||||||
|
|
||||||
|
namespace Ursa.Helpers;
|
||||||
|
|
||||||
|
public class FocusHelper
|
||||||
|
{
|
||||||
|
public static readonly AttachedProperty<bool> DialogFocusHintProperty =
|
||||||
|
AvaloniaProperty.RegisterAttached<FocusHelper, InputElement, bool>("DialogFocusHint");
|
||||||
|
|
||||||
|
public static void SetDialogFocusHint(InputElement obj, bool value) => obj.SetValue(DialogFocusHintProperty, value);
|
||||||
|
public static bool GetDialogFocusHint(InputElement obj) => obj.GetValue(DialogFocusHintProperty);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user