-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When you edit a status, it will now automatically focus into the stat…
…us message. You can use Enter to accept the change or Esc to discard it.
- Loading branch information
Showing
3 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
vrcosc-magicchatbox/Classes/XamlCommunication/TextBoxBehaviour.cs
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,61 @@ | ||
using System.Windows.Input; | ||
using System.Windows; | ||
using vrcosc_magicchatbox.ViewModels; | ||
using System.Windows.Controls; | ||
|
||
namespace vrcosc_magicchatbox.Classes | ||
{ | ||
public static class TextBoxBehaviour | ||
{ | ||
public static bool GetHandleEnterKey(DependencyObject obj) | ||
{ | ||
return (bool)obj.GetValue(HandleEnterKeyProperty); | ||
} | ||
|
||
public static void SetHandleEnterKey(DependencyObject obj, bool value) | ||
{ | ||
obj.SetValue(HandleEnterKeyProperty, value); | ||
} | ||
|
||
public static readonly DependencyProperty HandleEnterKeyProperty = | ||
DependencyProperty.RegisterAttached("HandleEnterKey", typeof(bool), typeof(TextBoxBehaviour), new PropertyMetadata(false, HandleEnterKeyPropertyChanged)); | ||
|
||
private static void HandleEnterKeyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | ||
{ | ||
if (d is TextBox textBox) | ||
{ | ||
textBox.KeyDown -= TextBox_KeyDown; | ||
|
||
if ((bool)e.NewValue) | ||
{ | ||
textBox.KeyDown += TextBox_KeyDown; | ||
} | ||
} | ||
} | ||
|
||
private static void TextBox_KeyDown(object sender, KeyEventArgs e) | ||
{ | ||
if (e.Key == Key.Escape || e.Key == Key.Enter) | ||
{ | ||
var textBox = sender as TextBox; | ||
var item = textBox.DataContext as StatusItem; | ||
if (item == null) return; | ||
|
||
if (e.Key == Key.Escape) | ||
{ | ||
// Run your logic to cancel the edit here | ||
item.editMsg = ""; | ||
item.IsEditing = false; | ||
} | ||
else if (e.Key == Key.Enter) | ||
{ | ||
// If enter is pressed, IsEditing is set to false | ||
item.editMsg = textBox.Text; | ||
item.IsEditing = false; | ||
} | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
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