×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    25

    Question How to creat Custom colored text in text block ?

    Hi all,

    I have scenario where I want to custom color some strings on text based on another text.

    For example color text match search keyword when I write search key word in another text box.

    I know I can use Run to do that but my problem that i get text from binding and the place of the string in text is changeable and based on search key word?

    Does anyone have idea how to do that ( in Xaml or C# code behind) ?

  2. #2
    Registered User
    Join Date
    Dec 2012
    Location
    Zagreb, Croatia
    Posts
    73

    Re: How to creat Custom colored text in text block ?

    There are several ways to do it actually. One way is to manipulate TextBlock.Inlines and construct your colored text.
    Another way is to create string with <Run> tags inside it and bind it to Text property.
    Yet another way is to use RichTextBox control.

    It really depends on what you want to do

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    25

    Re: How to creat Custom colored text in text block ?

    Quote Originally Posted by to_pe View Post
    There are several ways to do it actually. One way is to manipulate TextBlock.Inlines and construct your colored text.
    Another way is to create string with <Run> tags inside it and bind it to Text property.
    Yet another way is to use RichTextBox control.

    It really depends on what you want to do
    thanks for your replay my problem is that the part of text i want to give a dfferent color is based on search key word which is dynamic so i can not determine before where to put customized part of text .
    Last edited by Ahmed Emad; 2013-04-10 at 15:34.

  4. #4
    Registered User
    Join Date
    Dec 2012
    Location
    Zagreb, Croatia
    Posts
    73

    Re: How to creat Custom colored text in text block ?

    Well, you should redraw whenever search term changes anyway. You can either write event handlers, use multi binding (this isn't easy since it is not natively supported) or behaviors.

  5. #5
    Registered User
    Join Date
    Jan 2013
    Posts
    34

    Re: How to creat Custom colored text in text block ?

    One solution would be to create a custom text block control (deriving from TextBlock) that would be bound to a text and an highlight term. Whenever the text or highlight changes, the contents of the text block is invalidated and rebuilt.

  6. #6
    Registered User
    Join Date
    Feb 2013
    Posts
    25

    Re: How to creat Custom colored text in text block ?

    Quote Originally Posted by paulo.morgado View Post
    One solution would be to create a custom text block control (deriving from TextBlock) that would be bound to a text and an highlight term. Whenever the text or highlight changes, the contents of the text block is invalidated and rebuilt.
    ahighlight will be to the whole custom text block control?

  7. #7
    Registered User
    Join Date
    Dec 2012
    Location
    Zagreb, Croatia
    Posts
    73

    Re: How to creat Custom colored text in text block ?

    You would highlight only the parts you need highlighted.

  8. #8
    Registered User
    Join Date
    Feb 2013
    Posts
    25

    Re: How to creat Custom colored text in text block ?


Similar Threads

  1. Displaying custom text on E52 instead of date
    By lmocsi in forum Mobile Java General
    Replies: 5
    Last Post: 2012-05-07, 15:48
  2. Offscreen image and colored text not working
    By vahur12 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 5
    Last Post: 2010-07-25, 17:55
  3. Colored text in context sensitive help contents
    By jeetu_basai in forum Symbian User Interface
    Replies: 0
    Last Post: 2010-06-16, 05:36
  4. Custom text box..
    By vishwas_vincy11 in forum Symbian User Interface
    Replies: 2
    Last Post: 2006-09-13, 11:40
  5. Scrolling text in with a custom UI.
    By Subotai4Winds in forum Symbian C++
    Replies: 1
    Last Post: 2005-02-04, 05:02

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •