Example #1
0
        private void TBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (!string.IsNullOrEmpty(tBox.Text))
            {
                var children = StackPanel.Children.OfType <UIElement>().ToList();
                foreach (UIElement s in children)
                {
                    if (((CustomButton)s).TextMessage.Contains(tBox.Text) ||
                        ((CustomButton)s).TextName.Contains(tBox.Text))
                    {
                    }
                    else
                    {
                        StackPanel.Children.Remove(((CustomButton)s));
                    }
                }
            }
            else
            {
                List <LastMessageC> list =
                    Unpackage <LastMessageC> .Upackage(sw.GetLastMessageUser(Const.session));

                if (list != null)
                {
                    StackPanel.Children.Clear();
                    foreach (var l in list)
                    {
                        UserC user = new UserC();
                        user = sw.GetUserById(Const.session, swh.GetIdSecondUser(l));
                        DateTime     dt = DateTime.Parse(l.time);
                        CustomButton bt = new CustomButton
                        {
                            IdUser   = swh.GetIdSecondUser(l),
                            Template = (ControlTemplate)this.TryFindResource("BtTemplate")
                        };
                        if (l.idUserMessage == l.idSender)
                        {
                            bt.TextMessage   = "Вы: " + l.message;
                            bt.StatusMessage = -1;
                        }
                        else
                        {
                            bt.TextMessage   = l.message;
                            bt.StatusMessage = l.status;
                        }

                        bt.TextName     = user.name + " " + user.surname;
                        bt.TextSubname  = ("" + user.name[0] + user.surname[0]).ToUpper();
                        bt.TextTime     = dt.TimeOfDay.ToString();
                        bt.ColorMessage =
                            new SolidColorBrush(System.Windows.Media.Color.FromRgb(168, 168, 168));
                        bt.ColorName = new SolidColorBrush(System.Windows.Media.Color.FromRgb(34, 34, 34));
                        bt.ColorTime =
                            new SolidColorBrush(System.Windows.Media.Color.FromRgb(168, 168, 168));
                        bt.CountNewMessage = l.CountNewMessage.ToString();
                        StackPanel.Children.Add(bt);
                        Const.LastIdLastUser = sw.GetLastIdLastUser(Const.session);
                    }
                }
            }
        }