11< div >
22 < h1 > Text box suggestions</ h1 >
3- Documentation under construction
3+
4+ < h2 > Screenshots</ h2 >
5+ < img src ="https://raw.githubusercontent.com/spiegelp/MaterialDesignExtensions/master/screenshots/TextBoxSuggestions.png " alt ="Text box suggestions " />
6+
7+ < h2 > Code example</ h2 >
8+
9+ < p > Text box suggestions control</ p >
10+ < pre class ="language-markup "> < code class ="language-markup ">
11+ <mde:TextBoxSuggestions TextBoxSuggestionsSource="{Binding Path=TextBoxSuggestionsSource}">
12+ <TextBox Text="{Binding Path=Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
13+ </mde:TextBoxSuggestions>
14+ </ code > </ pre >
15+
16+ < p > Text box suggestions data source</ p >
17+ < pre class ="language-markup "> < code class ="language-markup ">
18+ public class TextBoxSuggestionsViewModel : ViewModel
19+ {
20+ private string _text;
21+ public string Text
22+ {
23+ get => _text;
24+ set
25+ {
26+ _text = value;
27+ OnPropertyChanged(nameof(Text));
28+ }
29+ }
30+
31+ private ITextBoxSuggestionsSource _textBoxSuggestionsSource;
32+ public ITextBoxSuggestionsSource TextBoxSuggestionsSource
33+ {
34+ get => _textBoxSuggestionsSource;
35+ }
36+
37+ public TextBoxSuggestionsViewModel() : base()
38+ {
39+ _textBoxSuggestionsSource = new OperatingSystemTextBoxSuggestionsSource();
40+ _text = null;
41+ }
42+ }
43+
44+ public class OperatingSystemTextBoxSuggestionsSource : TextBoxSuggestionsSource
45+ {
46+ private List< string > m_operatingSystemItems;
47+
48+ public OperatingSystemTextBoxSuggestionsSource()
49+ {
50+ m_operatingSystemItems = new List< string > ()
51+ {
52+ "Windows 7",
53+ "Windows 8",
54+ "Windows 8.1",
55+ "Windows 10"
56+ };
57+ }
58+
59+ public override IEnumerable< string > Search(string searchTerm)
60+ {
61+ searchTerm = searchTerm ?? string.Empty;
62+ searchTerm = searchTerm.ToLower();
63+
64+ return m_operatingSystemItems.Where(item => item.ToLower().Contains(searchTerm));
65+ }
66+ }
67+ </ code > </ pre >
468</ div >
0 commit comments