0
votes

I have to fire a datatrigger event and compare two fields & check whether its true & set a style for it based on it

Below is my code snippet

<DataTrigger Binding="{Binding SKUL.ItemNumber}"   Value="{Binding ActiveSKULNavigationItem.Supersession.Source}" >
<Setter Property="Common:ButtonPopup.ButtonContent" >
<Setter.Value >
 <Image Source="{StaticResource CommentHighlighted16}" Height="16" />
                                        </Setter.Value>
                                    </Setter>
                                </DataTrigger>

i want to check SKUL.ItemNumber equals ActiveSKULNavigationItem.Supersession.Source.But the above code throws error.

if i hardcode value="aaa" it works.

Error:A binding cannot be set on the value property of type datatrigger.A binding can only be set on a dependency property of a dependency object

How can i solve it

1

1 Answers

0
votes

The error shows clearly what you are doing wrong. You cannot bind value of DataTrigger. To solve this, add IValueConverter to your DataTrigger.Binding which will convert it to bool value. Code snippet:

<DataTrigger Binding="{Binding Converter={StaticResource myConverter}}" Value="True">

Converter (where MyItem is the class of bound object):

class MyConverter : IValueConverter 
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return (value as MyItem).SKUL.ItemNumber == (value as MyItem).ActiveSKULNavigationItem.Supersession.Source;
    }
}