views:

47

answers:

1

I have a WPF IM chat window with a input textbox and a output richtext box. I want to render input text on the richtext box. When user enter a smiley symbol like :) into the text block with some texts, I want to replace that text smiley with predefined smiley image and render on the richtext box. It's very similar to gtalk chat window behavior.

How can i do this? thanks in advance :-)

A: 

That's not easy. General approach would be to monitor rich text box input, find all emoticons and replace them with images: break Run where you found a smile into Span with Runs and Images. E.g.

  <RichTextBox>
    <FlowDocument>
     <Paragraph>
      <!-- Before -->
      <Run>Hello :) world!</Run>
      <!-- After -->
      <Span>
         <Run Text="Hello"/>
         <Image Width="16" Source="http://kolobok.us/smiles/light_skin/smile.gif"/&gt;
         <Run Text=" world"/>
       </Span>
     </Paragraph>
    </FlowDocument>
 </RichTextBox>

Hope this helps.

Anvaka
ok, In a chat window, we should append previous chats as well. so How can i do this using the code? not with xaml.
arlahiru