Wpf触发器(如果包含值)

编程入门 行业动态 更新时间:2024-10-28 02:20:20
本文介绍了Wpf触发器(如果包含值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好, 我有一个触发器:

Hello, I have a trigger:

<Style.Triggers> <DataTrigger Binding="{Binding Path=JOB_NUMBER}" Value="*MVR*"> <Setter Property="Foreground" Value="Red"></Setter> </DataTrigger> </Style.Triggers>

如果PRODUCT_NAME =L然后前景色将是红色。没关系。 我如何使用此触发器,如果​​不相等但包含此值。 例如: 123L-01 124L-01 细胞必须是红色的。 是否有某种替换角色? %L%? 你能提供一些解决方案吗? 我一直在寻找解决方案...... 谢谢!

If the PRODUCT_NAME = "L" then the foreground color will be red. That is okay. How can I use this trigger, if not equal but contains this value. For ex.: 123L-01 124L-01 Cells must have red. Is there some kind of replacement character? %L%? Could you offer some solution? I have been looking for solution for a long time... Thank you!

推荐答案

在所有更复杂的情况下,当依赖属性绑定到某些其他属性是不够的时候,例如在考虑某些条件的情况下,你必须触发代码隐藏中的属性修改,这与使用通常在代码中使用的属性一样简单,以响应您需要处理的事件。 -SA In all more complex cases when binding of the dependency property to some other properties is not enough, such as in case of taking some conditions into account, you have to trigger the property modification in code behind, which is as trivial as just using the property as it is usually used in code, in response to the event you need to handle.
—SA

所谓的价值转换器可能对你有帮助。 请看这里: www.wpftutorial/ValueConverters.html [ ^ ] 在Convert方法中,如果值包含'L',则必须返回'L' A so-called value converter might help you. Please have a look here: www.wpftutorial/ValueConverters.html[^] In the Convert method you must return 'L' if value contains 'L' using System; using System.Windows.Data; namespace SharepointWebServiceTest { class LConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if(value.ToString().Contains("L")) { return "L"; } else { return value; } } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } }

更多推荐

Wpf触发器(如果包含值)

本文发布于:2023-11-06 04:53:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1562760.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:触发器   Wpf

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!