Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have a trigger:

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



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!
Posted

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
 
Share this answer
 
A so-called value converter might help you.
Please have a look here:
http://www.wpftutorial.net/ValueConverters.html[^]
In the Convert method you must return 'L' if value contains 'L'
C#
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();
        }
    }
}
 
Share this answer
 
Comments
vrobi88 9-Mar-15 8:48am    
Thank you Guys!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900