问题描述
我想在RichTextBox中实现拼写检查功能,SpellCheck.IsEnabled="True"了,可还是实现不了,怎么弄啊?另外,如果我不想用WPF自带的拼写库的话,怎么自定义库,最好要有代码(前台和后台都要C#的),MSDN帮助看过了,上面没讲咋实现。
解决方案
解决方案二:
<Pagex:Class="SDKSample.SpellerCustomContextMenu"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Loaded="OnWindowLoaded"><TextBoxName="myTextBox"TextWrapping="Wrap"SpellCheck.IsEnabled="True"ContextMenuOpening="tb_ContextMenuOpening">Inacustummenuyouneedtowritecodetoaddspelerchoicesbecauseeverythinginacustomcontextmenuhastobeaddedexplicitly.</TextBox></Page>usingSystem;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Data;usingSystem.Windows.Documents;usingSystem.Windows.Media;usingSystem.Windows.Media.Imaging;usingSystem.Windows.Shapes;namespaceSDKSample{publicpartialclassSpellerCustomContextMenu:Page{voidOnWindowLoaded(objectsender,RoutedEventArgse){//ThisisrequiredforthefirsttimeContextMenuinvocationsothatTextEditordoesnthandleit.myTextBox.ContextMenu=GetContextMenu();}voidtb_ContextMenuOpening(objectsender,RoutedEventArgse){intcaretIndex,cmdIndex;SpellingErrorspellingError;myTextBox.ContextMenu=GetContextMenu();caretIndex=myTextBox.CaretIndex;cmdIndex=0;spellingError=myTextBox.GetSpellingError(caretIndex);if(spellingError!=null){foreach(stringstrinspellingError.Suggestions){MenuItemmi=newMenuItem();mi.Header=str;mi.FontWeight=FontWeights.Bold;mi.Command=EditingCommands.CorrectSpellingError;mi.CommandParameter=str;mi.CommandTarget=myTextBox;myTextBox.ContextMenu.Items.Insert(cmdIndex,mi);cmdIndex++;}SeparatorseparatorMenuItem1=newSeparator();myTextBox.ContextMenu.Items.Insert(cmdIndex,separatorMenuItem1);cmdIndex++;MenuItemignoreAllMI=newMenuItem();ignoreAllMI.Header="IgnoreAll";ignoreAllMI.Command=EditingCommands.IgnoreSpellingError;ignoreAllMI.CommandTarget=myTextBox;myTextBox.ContextMenu.Items.Insert(cmdIndex,ignoreAllMI);cmdIndex++;SeparatorseparatorMenuItem2=newSeparator();myTextBox.ContextMenu.Items.Insert(cmdIndex,separatorMenuItem2);}}//Getsafreshcontextmenu.privateContextMenuGetContextMenu(){ContextMenucm=newContextMenu();//CancreateSTATICcustommenuitemsifexistshere...MenuItemm1,m2,m3,m4;m1=newMenuItem();m1.Header="File";m2=newMenuItem();m2.Header="Save";m3=newMenuItem();m3.Header="SaveAs";m4=newMenuItem();m4.Header="RecentFiles";//Canaddfunctionalityforthecustommenuitemshere...cm.Items.Add(m1);cm.Items.Add(m2);cm.Items.Add(m3);cm.Items.Add(m4);returncm;}}}
解决方案三:
SpellCheck.IsEnabled="True"把文本导入,它就会显示出来。。。
解决方案四:
平台--------------------------------------------------------------------------------Windows7,WindowsVistaSP1或更高版本,WindowsXPSP3,WindowsServer2008(不支持服务器核心),WindowsServer2008R2(支持SP1或更高版本的服务器核心),WindowsServer2003SP2.NETFramework并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NETFramework系统要求。