将 TextBox 值传递给 Silverlight 3 中另一个数据绑定控件使用的 IValueConverter?
我有一个 Silverlight 3 控件,其中使用 ItemsControl 来显示项目列表。我已经实现了一个“过滤器”或“搜索”文本框,允许用户在控件上的文本框中输入搜索词,这会将 ItemsControl 中显示的项目限制为包含在文本框中输入的字符串的项目。我已经能够实现此功能,但我想通过更改项目控件中显示的文本中搜索词的文本颜色来增强它。例如,如果用户在搜索文本框中键入“foo”,我想将 ItemsControl 中的项目(我已经在这样做)过滤为包含“foo”的项目,并更改子字符串“foo”的背景颜色" 它出现在 ItemsControl 中的位置。
理想情况下,我将实现一个 IValueConverter 并将搜索文本框中的值作为参数传递给转换器。然后,转换器可以搜索正在转换的值并更改所有“foo”子字符串的背景颜色(不确定我将如何执行此操作,也许是内联的东西?)。看来传递给值转换器的参数值必须是静态资源。有什么方法可以将非静态值传递给值转换器来完成我想要做的事情吗?我是否应该采取另一种不使用 IValueConverter 的方法?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请注意,我还没有完全解决这个问题,但我在我的应用程序中使用 Interaction.Behaviors 做了一些类似的事情。这比直接转换器解决方案更灵活一些。在我的解决方案中,我使用它根据各种条件突出显示网格中的单元格和/或文本(例如,这是一个关键项目吗?将其设为红色)。
看一下这篇博客文章,它很好地解释了该过程,并且不仅仅适用于 Telerik RadGridView。 (仅供参考,我认为您需要添加对 System.Windows.Interactivity 的引用)
博客
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