문제

기본값에 메뉴 항목을 추가하고 싶습니다. ContextMenu a RichTextBox.

새로운 상황에 맞는 메뉴를 만들 수는 있지만 기본 메뉴에 표시되는 맞춤법 검사 제안을 잃어 버립니다.

모든 것을 다시 구현하지 않고 항목을 추가 할 수있는 방법이 있습니까?

도움이 되었습니까?

해결책

철자 제안, 자르기, 붙여 넣기 등으로 RichTextBox Context 메뉴를 다시 구현하는 것은 너무 까다 롭지 않습니다.

컨텍스트 메뉴 열기 이벤트를 다음과 같이 연결하십시오.

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);

필요에 따라 분리기를 추가하십시오. 새로운 맥락 메뉴 항목에이를 추가 한 다음 반짝이는 새로운 menuitems를 추가하십시오.

하지만 가까운 시일 내에 내가 할 일과 관련이 있기 때문에 실제 상황에 맞는 메뉴를 얻는 방법을 계속 찾고 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top