1行のAvalonEditコントロール(AcceptsReturn = "False"のTextBoxと同等)が必要です。AvalonEditのAcceptsReturn = "False"
AvalonEditはこのプロパティを持っていないようです。
AvalonEditではどうすればよいですか?
1行のAvalonEditコントロール(AcceptsReturn = "False"のTextBoxと同等)が必要です。AvalonEditのAcceptsReturn = "False"
AvalonEditはこのプロパティを持っていないようです。
AvalonEditではどうすればよいですか?
PreviewKeyDown
イベントを処理して、キーが返された場合はe.Handled
をtrueに設定することができます。
さらに、改行がテキスト領域に貼り付けられないようにしたいと思います。これは、次のことによって行わなければならない:
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
// Find the Paste command of the avalon edit
foreach (var commandBinding in textEditor.TextArea.CommandBindings.Cast<CommandBinding>())
{
if (commandBinding.Command == ApplicationCommands.Paste)
{
// Add a custom PreviewCanExecute handler so we can filter out newlines
commandBinding.PreviewCanExecute += new CanExecuteRoutedEventHandler(pasteCommandBinding_PreviewCanExecute);
break;
}
}
}
void pasteCommandBinding_PreviewCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
// Get clipboard data and stuff
var dataObject = Clipboard.GetDataObject();
var text = (string)dataObject.GetData(DataFormats.UnicodeText);
// normalize newlines so we definitely get all the newlines
text = TextUtilities.NormalizeNewLines(text, Environment.NewLine);
// if the text contains newlines - replace them and paste again :)
if (text.Contains(Environment.NewLine))
{
e.CanExecute = false;
e.Handled = true;
text = text.Replace(Environment.NewLine, " ");
Clipboard.SetText(text);
textEditor.Paste();
}
}
は、ここに私のEditor.TextArea.PreviewKeyDownハンドラです:
private void TabToOkayBtn(object sender, KeyEventArgs args)
{
if (args.Key == Key.Tab)
{
args.Handled = true;
Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() => // input priority is always needed when changing focus
_editor.TextArea.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next))));
}
}
ます。また、「前」との使用に行くためのシフト状態をチェックすることができます方向を選択する三項演算子:
var shiftPressed = (args.KeyboardDevice.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift;