コード例 #1
0
ファイル: AutoComplete.cs プロジェクト: ichttt/Twice
        private void AssociatedObject_TextInput(object sender, TextCompositionEventArgs e)
        {
            var text = e.Text;

            if (text.StartsWith(Constants.Twitter.HashTag, StringComparison.Ordinal))
            {
                FilterText = string.Empty;
                AutoCompletePopup.IsOpen      = true;
                AutoCompleteBox.ItemsSource   = FilteredHashtags;
                AutoCompleteBox.SelectedIndex = 0;
                Mode = SourceMode.Hashtags;
            }
            else if (text.StartsWith(Constants.Twitter.Mention, StringComparison.Ordinal))
            {
                FilterText = string.Empty;
                AutoCompletePopup.IsOpen      = true;
                AutoCompleteBox.ItemsSource   = FilteredUsers;
                AutoCompleteBox.SelectedIndex = 0;
                Mode = SourceMode.Users;
            }
            else if (AutoCompletePopup.IsOpen)
            {
                string selectedText = (string)AutoCompleteBox.SelectedItem;

                FilterText += text;

                var items = FilteredItems.ToList();

                Debug.WriteLine(string.Join(" - ", items));

                AutoCompleteBox.ItemsSource   = items;
                AutoCompleteBox.SelectedIndex = items.IndexOf(selectedText);
                if (AutoCompleteBox.SelectedIndex < 0)
                {
                    AutoCompleteBox.SelectedIndex = 0;
                }
                AutoCompleteBox.InvalidateProperty(ItemsControl.ItemsSourceProperty);
            }
        }