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?
Printable View
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?
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.
Hey, thanks for the advice.. I know it would be ideal to keep both separate, but not sure how.
My ObservableCollection class:
MyText will be the text to display in the column..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; }
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.
*BUMP*
Anyone? Does anybody know how to do this?!
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 :)