Make part of a ListViewItem text bold?

xera

Expert Member
Joined
Jun 15, 2007
Messages
2,330
Reaction score
158
Location
Home is where the heart is
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 xaml, and am not sure how to do it.

My ListView is bound to an ObservableCollection.

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.

Any ideas?
 
Last edited:
Not sure this is possible without using a richtextbox + they not ideal as they don't support binding.

If it's something to will be using frequently then I think you would most likely need a custom control - you could develop it (refer codeproject, codeplex, ...); or look for a professional control that provides what you want at sites like devexpress, telerik, ...
 
This might be a good time to think of refactoring and datatemplates.
 
Thanks guys.... 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 :)
 
Top
Sign up to the MyBroadband newsletter
X