WPF 文本拼写检查 分类: .NET 2012-05-23 15:30 666人阅读 评论(0) 收藏

开发环境:xp sp3、vs2010、.net4.0(.net3.5没有SpellCheck.CustomDictionaries)



代码:

<Window x:Class="aaa.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=System"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TextBox x:Name="txtBox" SpellCheck.IsEnabled="True" Language="en-us"   Margin="24,17,0,0" Height="19" VerticalAlignment="Top" HorizontalAlignment="Left" Width="211">
            <SpellCheck.CustomDictionaries>
                <sys:Uri>pack://application:,,,/lexicon/word.lex</sys:Uri>
            </SpellCheck.CustomDictionaries>
        </TextBox>
    </Grid>
</Window>


因为文本框中的单词WPF并不是错误,只是系统不能识别这个单词,所以通过自定义字典来解决这个问题,

首先打开Notepad 编写词典文件(.lex),在文件中按以下格式编写单词内容(关于语言对应的ID请参考http://msdn.microsoft.com/en-us/goglobal/bb964664.aspx):

#LID 1033
WPF
Word2
Word3


将字典文件放到项目的lexicon目录下:


备注:单纯的文字拼写检查本人验证过,但自定义字典没有成功,在xaml中编辑代码时发现sys下没有Uri,不知道怎么回事,有知道的请告知下,在此感谢!


文章参考:http://www.cnblogs.com/gnielee/archive/2010/05/04/1727133.html

版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2012-05-23 15:30  哲夫  阅读(148)  评论(0编辑  收藏  举报