Search code examples
c#wpfxaml.net-4.0datatrigger

How to bind DataTrigger to an Interface property


I have 4 class which implement my custom ICalendarItem Interface. That interface has a property called 'Jours'.

ObservableCollection<KeyValuePair<DateTime, DateTime>> Jours;

My class override that property like this :

public override ObservableCollection<KeyValuePair<DateTime, DateTime>> Jours {...}

When the Jours.Count goes from 0 to 1, i want to trigger an action so i tried this :

<DataTrigger Binding="{Binding Path=Jours.Count}" Value="1">

<DataTrigger Binding="{Binding Path=(ICalendarItem)Jours.Count}" Value="1">

None of these 2 DataTrigger works.

Anyone know how to bind a DataTrigger to an Interface property?


Solution

  • When you want to specifically bind to a custom interface property, you need to place place the namespace, interface and property name within parenthesis. You can then reference a sub-property like Count outside of the parenthesis.

    <DataTrigger Binding="{Binding Path=(local:ICalendarItem.Jours).Count}" Value="1">
    ...
    </DataTrigger>