本文介绍了Wpf触发器(如果包含值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
—SA
你好, 我有一个触发器:
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.
所谓的价值转换器可能对你有帮助。 请看这里: 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触发器(如果包含值)
发布评论