한 줄 AvalonEdit 컨트롤 (AcceptsReturn = "False"인 TextBox와 동일)이 필요합니다.AvalonEdit의 AcceptsReturn = "False"
AvalonEdit에는이 속성이없는 것으로 보입니다.
어떻게 AvalonEdit에 대해이 작업을 수행합니까?
한 줄 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;