private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Emoji.Wpf.TextBlock textBlock    = sender as Emoji.Wpf.TextBlock;
            SolidColorBrush     matchedBrush = new SolidColorBrush(Colors.Green);

            // Only proceed if this TextBlock hasn't already been matched.
            if (textBlock.Background == null)
            {
                if (findingMatch == false)
                {
                    // If this is the first emoji of the pair
                    textBlock.Text       = Convert.ToString(textBlock.Tag);
                    lastTextBlockClicked = textBlock;
                    findingMatch         = true;
                }
                else if (textBlock.Tag == lastTextBlockClicked.Tag &&
                         textBlock.Name != lastTextBlockClicked.Name)
                {
                    // If the second emoji matches the first emoji
                    matchesFound++;
                    textBlock.Text = Convert.ToString(textBlock.Tag);
                    lastTextBlockClicked.Background = matchedBrush;
                    textBlock.Background            = matchedBrush;
                    findingMatch = false;
                }
                else
                {
                    // If the second emoji doesn't match the first
                    lastTextBlockClicked.Text = "?";
                    findingMatch = false;
                }
            }
        }
Exemple #2
0
        void NewMessage(string sender, string message)
        {
            Border b = new Border();

            b.CornerRadius = new CornerRadius(8);
            b.BorderBrush  = (sender == Form1.myname) ? Brushes.DarkGreen : Brushes.Gray;
            if (sender == "Teacher")
            {
                b.BorderBrush = Brushes.DarkRed;
            }
            b.BorderThickness = new Thickness(2);

            Frame container = new Frame();
            //b.Margin = new Thickness(5,5,5,0);
            StackPanel msg   = new StackPanel();
            WrapPanel  panel = new WrapPanel();
            Label      sndr  = new Label();

            sndr.FontSize               = 11;
            sndr.Foreground             = (sender == Form1.myname) ? Brushes.DarkGreen : Brushes.DarkGray;
            container.MouseDoubleClick += Container_MouseDoubleClick;
            TextBlock mesg = new TextBlock();

            mesg.Text         = message;
            mesg.TextWrapping = TextWrapping.Wrap;
            mesg.FontSize     = 16;
            mesg.FontFamily   = new FontFamily("Times New Roman");
            mesg.Foreground   = Brushes.Black;
            mesg.Margin       = new Thickness(3, 0, 3, 3);
            sndr.Content      = sender;
            if (ia(message[0]))
            {
                mesg.FlowDirection = FlowDirection.RightToLeft;
            }
            msg.Children.Add(sndr);
            msg.Children.Add(mesg);
            container.Content = msg;

            b.Child = container;
            WrapPanel wp = new WrapPanel();

            wp.Margin = new Thickness(5, 5, 5, 0);
            wp.Children.Add(b);
            MessageList.Children.Add(wp);
            scrollViewer.ScrollToEnd();
        }