views:

21

answers:

1

I have a Silverlight 3 control where I am using an ItemsControl to display a list of items. I have implemented a "filter" or "search" textbox that allows the user to enter a search term in a textbox on the control that will limit the items displayed in the ItemsControl to ones that contain the string entered in the textbox. I have been able to implement this functionality, but I'd like to enhance it by changing the color of the text of the search term in the text that is displayed in the items control. For example, if the user types "foo" in the search textbox, I would like to filter the items in the ItemsControl (which I am already doing) to items that contain "foo", and change the background color of the substring "foo" where it occurs in the ItemsControl.

Ideally, I would implement an IValueConverter and pass the value in the search textbox as the parameter to the converter. The converter could then search through the value that is being converted and change the background color of all "foo" substrings (not sure how I'm going to do this yet, something with Inlines maybe?). It seems parameter values passed to value converters must be static resources. Is there any way I can pass a non-static value to the value converter to accomplish what I'm trying to do? Is there another way I should be going about this that does not use an IValueConverter?

A: 

Mind you I haven't worked this out completely yet, but I do something sort of similar in my app using Interaction.Behaviors. This is a little more flexible than a straight converter solution. In my solution, I use it to highlight cells and/or text in a grid based on various conditions (e.g. is this a critical item? Make it red).

Take a look at this blog entry, it explains the process fairly well, and should apply to more than just a Telerik RadGridView. (FYI, I think you'll need to add a reference to System.Windows.Interactivity)

Blog

Todd Davis
I don't think this will work in my case. For one, those color-changing rules seem to be static, meaning they don't depend on the state of any other controls. I need a solution that allows the conversion rules to depend on the text that is entered in another textbox. The other thing is that Telerik grid exposes a "RowLoaded" event for which there is no equivalent on an ItemsControl. That way seems more "ASP.NET-ish" if you know what I mean (using a databound control and handling an event to format the data as each item in the datasource is bound to a new row).
KOTJMF