2008-09-10 11 views
19

In WPF, un DataTrigger può essere associato a una proprietà associata?È possibile associare un DataTrigger a una proprietà associata?

In sostanza, voglio utilizzare un convertitore su una proprietà associata per fornire uno stile quando una particolare regola di convalida è stata interrotta. Sto usando markup simile al seguente:

<DataTrigger Binding="{Binding Path=Validation.Errors, 
         RelativeSource={RelativeSource Self}, 
         Converter={StaticResource RequiredToBoolConverter}}" 
         Value="True"> 
    <Setter Property="Background" Value="LightGreen" /> 
</DataTrigger> 

Tuttavia, quando questo viene eseguito, ottengo il seguente:

System.Windows.Data Error: 39 : BindingExpression path error: 'Validation' property not found on 'object' ''TextBox' (Name='')'. BindingExpression:Path=Validation.Errors; DataItem='TextBox' (Name=''); target element is 'TextBox' (Name=''); target property is 'NoTarget' (type 'Object')

Se cambio DataTrigger percorso vincolante per "Testo", non ho ricevuto la errore di database (ma ovviamente non fornisce il comportamento che sto cercando).

risposta

27

È necessario avvolgere la struttura in parentesi:

<DataTrigger Binding="{Binding Path=(Validation.Errors).YourAttachedProperty,... 
+4

Questo è documentato su MSDN a http://msdn.microsoft.com/en-us/library/ms752300.aspx#Path_Syntax –

+0

@M. Dudley il link non funziona più! –

+2

Nuovo link: https://msdn.microsoft.com/library/ms752300%28v=vs.100%29.aspx#Path_Syntax –

Problemi correlati