Results 1 to 5 of 5

Thread: [RESOLVED] Make part of a ListViewItem text bold?

  1. #1

    Thread Starter
    Lively Member xera's Avatar
    Join Date
    Nov 2006
    Location
    SA
    Posts
    104

    Resolved [RESOLVED] Make part of a ListViewItem text bold?

    From what I know, I think I should add text to a TextBlock, set part of the text as bold, then set it to the ListViewItem. Problem is, I'm doing this in code, and not sure how to do it.

    My ListView is bound to an ObservableCollection.

    Any ideas?
    Did you know... ..that you live in a Universe?!
    Code:
    var Answer = Uni + Verse = single + spoken + sentence;


    Life is amusing...

  2. #2
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: Make part of a ListViewItem text bold?

    Quote Originally Posted by xera View Post
    Problem is, I'm doing this in code
    Yep, you said it. Remember that you're working with WPF. If you're writing code that is manipulating the UI, you're probably doing it wrong.

    To "do" WPF you need to separate your UI visuals and your application logic. So you have an ObservableCollection of... whats? The things you put in that collection should be classes that represent something meaningful in your problem domain, allowing you to use a DataTemplate on the XAML side to make them appear however you want.

    Without knowing a bit more about what you're trying to achieve it's difficult to give you more than general advice, so if the above doesn't help much, please give a bit more information about your problem.

  3. #3

    Thread Starter
    Lively Member xera's Avatar
    Join Date
    Nov 2006
    Location
    SA
    Posts
    104

    Re: Make part of a ListViewItem text bold?

    Hey, thanks for the advice.. I know it would be ideal to keep both separate, but not sure how.

    My ObservableCollection class:

    Code:
    public string MyText { get; set; }
    
    public int idx1Start { get; set; }
    public int idx1Stop { get; set; }
    
    public int idx2Start { get; set; }
    public int idx2Stop { get; set; }
    MyText will be the text to display in the column..

    idx1Start and idx1Stop will be the start and stop respectively of the 1st bold substring in MyText.
    idx2Start and idx2Stop will be the start and stop respectively of the 2nd bold substring in MyText.
    Did you know... ..that you live in a Universe?!
    Code:
    var Answer = Uni + Verse = single + spoken + sentence;


    Life is amusing...

  4. #4

    Thread Starter
    Lively Member xera's Avatar
    Join Date
    Nov 2006
    Location
    SA
    Posts
    104

    Re: Make part of a ListViewItem text bold?

    *BUMP*


    Anyone? Does anybody know how to do this?!
    Did you know... ..that you live in a Universe?!
    Code:
    var Answer = Uni + Verse = single + spoken + sentence;


    Life is amusing...

  5. #5

    Thread Starter
    Lively Member xera's Avatar
    Join Date
    Nov 2006
    Location
    SA
    Posts
    104

    Re: Make part of a ListViewItem text bold?

    Good news!! After more searching around browsing examples, I have finally come across a possible solution.

    The solution is to use a DataTemplate, which contains multiple TextBlock's, formatted in this order: Regular, Bold, Regular, Bold, Regular.
    With that format, I should be able to split the string in the code, and bind the various parts to the various TextBlock's.

    It looks like it'll work for now... But if anyone has a better idea, please let me know
    Did you know... ..that you live in a Universe?!
    Code:
    var Answer = Uni + Verse = single + spoken + sentence;


    Life is amusing...

Posting Permissions

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



Click Here to Expand Forum to Full Width