I want to activate a trigger if the bound items property ID is equal to a property in my custom control.
But i can't use bindings in my triggers!
How would i do this?
I want to activate a trigger if the bound items property ID is equal to a property in my custom control.
But i can't use bindings in my triggers!
How would i do this?
DataTrigger's value property doesn't take bindings?
<DataTrigger Binding="{Binding BoundPropertyId}" Value="{Binding ElementName=Mine, Path=Property}" />
If that doesn't work, you might need to hook onto an event and process it yourself in the code-behind.
This should work:
<DataTrigger
Value="True">
<DataTrigger.Binding>
<MultiBinding
Converter="{x:Static local:EqualityConverter.Instance}">
<Binding
Path="BoundProperty" />
<Binding
ElementName="MockCustomControl"
Path="Text" />
</MultiBinding>
</DataTrigger.Binding>
<DataTrigger.Setters>
<Setter
TargetName=" ... "
Property=" ... "
Value=" ... " />
...
...
</DataTrigger.Setters>
</DataTrigger>
And the converter may be something similar to this:
public class EqualityConverter : IMultiValueConverter
{
public static readonly EqualityConverter Instance = new EqualityConverter();
#region IMultiValueConverter Members
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (values == null || values.Length == 0) return false;
for (int i = 1; i < values.Length; i++)
if (!values[i].Equals(values[0])) return false;
return true;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
Note that I've used a generic convrter that can campare n values, but you can use a simple one as per your needs.
Hope this helps.