-
Notifications
You must be signed in to change notification settings - Fork 2
/
MainViewModel.cs
67 lines (55 loc) · 2.79 KB
/
MainViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using DevExpress.Mvvm;
using DevExpress.Xpf.SpellChecker;
using DevExpress.XtraSpellChecker;
using System;
using System.Globalization;
namespace DXSpellCheckerBindingDictionaries.ViewModel
{
public class MainViewModel
{
public virtual DictionarySourceCollection Dictionaries { get; set; }
public virtual SpellChecker SpellChecker { get; set; }
protected virtual IMessageBoxService MessageBoxService { get { return null; } }
public MainViewModel()
{
// Create a SpellChecker class instance.
SpellChecker = new SpellChecker();
// Specify the SpellChecker's properties.
SpellChecker.SpellingFormType = SpellingFormType.Word;
SpellChecker.SpellCheckMode = SpellCheckMode.AsYouType;
SpellChecker.Culture = new CultureInfo("de-DE");
// Obtain a dictionary collection.
Dictionaries = GetDictionaries();
// Subscribe to events
SpellChecker.RepeatedWordFound += SpellChecker_RepeatedWordFound;
SpellChecker.CheckCompleteFormShowing += SpellChecker_CheckCompleteFormShowing;
}
private void SpellChecker_CheckCompleteFormShowing(object sender, FormShowingEventArgs e)
{
MessageBoxService.Show("That's It!");
e.Handled = true;
}
private void SpellChecker_RepeatedWordFound(object sender, RepeatedWordFoundEventArgs e)
{
e.Result = SpellCheckOperation.Cancel;
}
public DictionarySourceCollection GetDictionaries()
{
// Create a dictionary collection.
var collection = new DictionarySourceCollection();
// Create a Hunspell spell-checking dictionary.
var dictionary = new HunspellDictionarySource() { Culture = new CultureInfo("de-DE") };
// Load the dictionary file.
dictionary.DictionaryUri = new Uri(@"pack://application:,,,/DXSpellCheckerBindingDictionaries;component/Dictionaries/de_DE.dic");
// Load the affix file.
dictionary.GrammarUri = new Uri(@"pack://application:,,,/DXSpellCheckerBindingDictionaries;component/Dictionaries/de_DE.aff");
// Add the dictionary to the collection.
collection.Add(dictionary);
var customDictionary = new SpellCheckerCustomDictionarySource() { Culture = new CultureInfo("EN-us") };
customDictionary.DictionaryUri = new Uri(@"pack://application:,,,/DXSpellCheckerBindingDictionaries;component/Dictionaries/CustomEnglish.dic");
customDictionary.AlphabetUri = new Uri(@"pack://application:,,,/DXSpellCheckerBindingDictionaries;component/Dictionaries/Alphabet.txt");
collection.Add(customDictionary);
return collection;
}
}
}