RichTextBox
의 기본값 인 ContextMenu
에 메뉴 항목을 추가하고 싶습니다.기본 컨텍스트 메뉴에 메뉴 항목 추가
새 컨텍스트 메뉴를 만들 수 있지만 기본 메뉴에 나타나는 맞춤법 검사 제안이 손실 될 수 있습니다.
모든 항목을 다시 구현하지 않고 항목을 추가하는 방법이 있습니까?
RichTextBox
의 기본값 인 ContextMenu
에 메뉴 항목을 추가하고 싶습니다.기본 컨텍스트 메뉴에 메뉴 항목 추가
새 컨텍스트 메뉴를 만들 수 있지만 기본 메뉴에 나타나는 맞춤법 검사 제안이 손실 될 수 있습니다.
모든 항목을 다시 구현하지 않고 항목을 추가하는 방법이 있습니까?
그것은 등 맞춤법 제안, 잘라 내기, 붙여 넣기로하여 RichTextBox의 상황에 맞는 메뉴를 구현할 너무 까다로운 아니라
다음과 같이 상황에 맞는 메뉴 오프닝 이벤트를 연결 : 이벤트 핸들러 빌드 내
AddHandler(RichTextBox.ContextMenuOpeningEvent, new ContextMenuEventHandler(RichTextBox_ContextMenuOpening), true);
을 필요에 따라 컨텍스트 메뉴. 다음으로 기존의 상황에 맞는 메뉴의 메뉴 항목을 다시 만들 수 있습니다 : 철자 오류가있는 경우
는private IList<MenuItem> GetSpellingSuggestions() { List<MenuItem> spellingSuggestions = new List(); SpellingError spellingError = myRichTextBox.GetSpellingError(myRichTextBox.CaretPosition); if (spellingError != null) { foreach (string str in spellingError.Suggestions) { MenuItem mi = new MenuItem(); mi.Header = str; mi.FontWeight = FontWeights.Bold; mi.Command = EditingCommands.CorrectSpellingError; mi.CommandParameter = str; mi.CommandTarget = myRichTextBox; spellingSuggestions.Add(mi); } } return spellingSuggestions; } private IList<MenuItem> GetStandardCommands() { List<MenuItem> standardCommands = new List(); MenuItem item = new MenuItem(); item.Command = ApplicationCommands.Cut; standardCommands.Add(item); item = new MenuItem(); item.Command = ApplicationCommands.Copy; standardCommands.Add(item); item = new MenuItem(); item.Command = ApplicationCommands.Paste; standardCommands.Add(item); return standardCommands; }
, 당신은 모두 무시로 만들 수 있습니다 : 필요에 따라
MenuItem ignoreAllMI = new MenuItem(); ignoreAllMI.Header = "Ignore All"; ignoreAllMI.Command = EditingCommands.IgnoreSpellingError; ignoreAllMI.CommandTarget = textBox; newContextMenu.Items.Add(ignoreAllMI);
는 구분을 추가합니다. 새로운 컨텍스트 메뉴 항목에 추가 한 다음 반짝이는 새 MenuItem을 추가하십시오.
저는 실제 컨텍스트 메뉴를 얻을 수있는 방법을 찾고 있습니다. 이는 가까운 장래에 작업 할 내용과 관련이 있습니다.
감사합니다. Donnelle. 아마 다시 구현할 것이라고 생각했습니다. 이 작업을 수행하는 방법에 대한 정보를 제공해 주셔서 감사합니다! – dmo
매우 유사한 예제는 MSDN에서도 직접 찾을 수 있습니다. http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.getspellingerror(v=vs.110).aspx –
@ Donnelle 파티에 늦어서 미안 하긴하지만, WPF 태그가있는이 질문과 똑같은 문제 (단순한 텍스트 상자가있는 시나리오 제외)에 직면하고 있기 때문에 좀 더 "XAMLish"방법을 제공 할 수 있습니까? – Yoda