コード例 #1
0
        private async void ChatMessageTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                this.HideIntellisense();

                string tag = this.ChatMessageTextBox.Text.Split(' ').LastOrDefault();
                if (!string.IsNullOrEmpty(tag))
                {
                    if (tag.StartsWith("@"))
                    {
                        string filter = tag.Substring(1);

                        List <UserViewModel> users = (await ChannelSession.ActiveUsers.GetAllUsers()).ToList();
                        if (!string.IsNullOrEmpty(filter))
                        {
                            users = users.Where(u => !string.IsNullOrEmpty(u.UserName) && u.UserName.StartsWith(filter, StringComparison.InvariantCultureIgnoreCase)).ToList();
                        }
                        users = users.OrderBy(u => u.UserName).Take(5).Reverse().ToList();

                        if (users.Count > 0)
                        {
                            this.indexOfTag = this.ChatMessageTextBox.Text.LastIndexOf(tag);
                            UsernameIntellisenseListBox.ItemsSource = users;

                            // Select the bottom user
                            UsernameIntellisenseListBox.SelectedIndex = users.Count - 1;

                            Rect  positionOfCarat = this.ChatMessageTextBox.GetRectFromCharacterIndex(this.ChatMessageTextBox.CaretIndex, true);
                            Point topLeftOffset   = this.ChatMessageTextBox.TransformToAncestor(this).Transform(new Point(positionOfCarat.Left, positionOfCarat.Top));

                            ShowUserIntellisense(topLeftOffset.X, topLeftOffset.Y, users.Count);
                        }
                    }
                    else
                    {
                        List <EmoticonImage> emoticonImages = ShouldSendAsStreamer() ?
                                                              ChannelSession.FindMatchingEmoticonsForUser(tag).ToList() :
                                                              ChannelSession.FindMatchingEmoticonsForBot(tag).ToList();
                        if (emoticonImages.Count > 0)
                        {
                            emoticonImages  = emoticonImages.Take(5).Reverse().ToList();
                            this.indexOfTag = this.ChatMessageTextBox.Text.LastIndexOf(tag);
                            EmoticonIntellisenseListBox.ItemsSource = emoticonImages;

                            // Select the bottom icon
                            EmoticonIntellisenseListBox.SelectedIndex = emoticonImages.Count - 1;

                            Rect  positionOfCarat = this.ChatMessageTextBox.GetRectFromCharacterIndex(this.ChatMessageTextBox.CaretIndex, true);
                            Point topLeftOffset   = this.ChatMessageTextBox.TransformToAncestor(this).Transform(new Point(positionOfCarat.Left, positionOfCarat.Top));

                            ShowEmoticonIntellisense(topLeftOffset.X, topLeftOffset.Y, emoticonImages.Count);
                        }
                    }
                }
            }
            catch (Exception ex) { Logger.Log(ex); }
        }