-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #705 from b-editor/improve-xaml
XAMLの改善
- Loading branch information
Showing
14 changed files
with
784 additions
and
803 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Input; | ||
using Avalonia.Interactivity; | ||
using Avalonia.LogicalTree; | ||
|
||
namespace Beutl.Controls; | ||
|
||
public static class TextBoxAttachment | ||
{ | ||
public static readonly AttachedProperty<EnterBehaviorMode> EnterDownBehaviorProperty = | ||
AvaloniaProperty.RegisterAttached<TextBox, EnterBehaviorMode>("EnterDownBehavior", typeof(TextBoxAttachment), EnterBehaviorMode.None); | ||
|
||
static TextBoxAttachment() | ||
{ | ||
EnterDownBehaviorProperty.Changed.Subscribe(ev => | ||
{ | ||
if (ev.Sender is TextBox tb && ev.NewValue.HasValue) | ||
{ | ||
if (ev.NewValue.Value != EnterBehaviorMode.None) | ||
{ | ||
tb.AddHandler(InputElement.KeyDownEvent, OnTextBoxKeyDown, RoutingStrategies.Tunnel); | ||
} | ||
else | ||
{ | ||
tb.RemoveHandler(InputElement.KeyDownEvent, OnTextBoxKeyDown); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
public enum EnterBehaviorMode | ||
{ | ||
None, | ||
LostFocus, | ||
Auto | ||
} | ||
|
||
public static EnterBehaviorMode GetEnterDownBehavior(TextBox obj) | ||
{ | ||
return obj.GetValue(EnterDownBehaviorProperty); | ||
} | ||
|
||
public static void SetEnterDownBehavior(TextBox obj, EnterBehaviorMode value) | ||
{ | ||
obj.SetValue(EnterDownBehaviorProperty, value); | ||
} | ||
|
||
private static void OnTextBoxKeyDown(object sender, KeyEventArgs e) | ||
{ | ||
if (sender is TextBox tb | ||
&& e.Key == Key.Enter) | ||
{ | ||
EnterBehaviorMode mode = GetEnterDownBehavior(tb); | ||
if (mode == EnterBehaviorMode.None) return; | ||
if (mode == EnterBehaviorMode.Auto && tb.AcceptsReturn && !e.KeyModifiers.HasFlag(KeyModifiers.Control)) return; | ||
|
||
foreach (InputElement item in tb.GetLogicalSiblings().SkipWhile(v => v != tb).Skip(1).OfType<InputElement>()) | ||
{ | ||
if (item.Focus()) | ||
{ | ||
e.Handled = true; | ||
return; | ||
} | ||
} | ||
|
||
|
||
foreach (InputElement item in tb.GetLogicalAncestors().OfType<InputElement>()) | ||
{ | ||
if (item.Focus()) | ||
{ | ||
e.Handled = true; | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters