C# 拼写检查数据网格单元
我想知道如何动态地使用拼写检查datagrid的每个单元格(不是在xaml中,而是在cs中) 我已经试过类似的方法了,但是不起作用C# 拼写检查数据网格单元,c#,datagrid,spell-checking,C#,Datagrid,Spell Checking,我想知道如何动态地使用拼写检查datagrid的每个单元格(不是在xaml中,而是在cs中) 我已经试过类似的方法了,但是不起作用 public static void SpellCheck(System.Windows.Controls.DataGrid MyDataGrid) { for (int i = 0; i < MyDataGrid.Items.Count; i++) { for (int j = 0; j &l
public static void SpellCheck(System.Windows.Controls.DataGrid MyDataGrid)
{
for (int i = 0; i < MyDataGrid.Items.Count; i++)
{
for (int j = 0; j < MyDataGrid.Columns.Count; j++)
{
System.Windows.Controls.TextBox tb = MyDataGrid.GetCell(i, j).Content as System.Windows.Controls.TextBox;
tb.SpellCheck.IsEnabled = true;
}
}
}
有人能帮我吗?
提前谢谢你经过一些研究,我找到了一个解决方案(使用NetSpell),但它需要改进,我愿意接受任何建议。多谢各位
public static void SpellCheck(System.Windows.Controls.DataGrid MyDataGrid)
{
TextBlock content;
string phrase;
string[] longtext;
NetSpell.SpellChecker.Dictionary.WordDictionary oDict = new NetSpell.SpellChecker.Dictionary.WordDictionary();
oDict.DictionaryFile = "fr-FR.dic";
oDict.Initialize();
NetSpell.SpellChecker.Spelling oSpell = new NetSpell.SpellChecker.Spelling();
oSpell.Dictionary = oDict;
for (int i = 0; i < MyDataGrid.Items.Count; i++)
{
for (int j = 0; j < MyDataGrid.Columns.Count; j++)
{
content = MyDataGrid.GetCell(i, j).Content as TextBlock;
phrase = content.Text;
longtext = phrase.Split(' ');
content.Inlines.Clear();
for (int k = 0; k < longtext.Length; k++)
{
if (!oSpell.TestWord(longtext[k]))
{
//Word does not exist in dictionary
content.Inlines.Add(new Run(longtext[k] + " ") { Foreground = Brushes.Red });
}
else content.Inlines.Add(new Run(longtext[k] + " "));
}
}
}
}
公共静态无效拼写检查(System.Windows.Controls.DataGrid MyDataGrid)
{
文本块内容;
字符串短语;
字符串[]长文本;
NetSpell.SpellChecker.Dictionary.WordDictionary oDict=新建NetSpell.SpellChecker.Dictionary.WordDictionary();
oDict.DictionaryFile=“fr-fr.dic”;
oDict.Initialize();
NetSpell.SpellChecker.Spelling oSpell=新建NetSpell.Spelling checker.Spelling();
oSpell.Dictionary=oDict;
对于(int i=0;i
public static void SpellCheck(System.Windows.Controls.DataGrid MyDataGrid)
{
TextBlock content;
string phrase;
string[] longtext;
NetSpell.SpellChecker.Dictionary.WordDictionary oDict = new NetSpell.SpellChecker.Dictionary.WordDictionary();
oDict.DictionaryFile = "fr-FR.dic";
oDict.Initialize();
NetSpell.SpellChecker.Spelling oSpell = new NetSpell.SpellChecker.Spelling();
oSpell.Dictionary = oDict;
for (int i = 0; i < MyDataGrid.Items.Count; i++)
{
for (int j = 0; j < MyDataGrid.Columns.Count; j++)
{
content = MyDataGrid.GetCell(i, j).Content as TextBlock;
phrase = content.Text;
longtext = phrase.Split(' ');
content.Inlines.Clear();
for (int k = 0; k < longtext.Length; k++)
{
if (!oSpell.TestWord(longtext[k]))
{
//Word does not exist in dictionary
content.Inlines.Add(new Run(longtext[k] + " ") { Foreground = Brushes.Red });
}
else content.Inlines.Add(new Run(longtext[k] + " "));
}
}
}
}