2008-09-10 34 views
19

WPFでは、DataTriggerが添付プロパティにバインドできますか?DataTriggerを添付プロパティにバインドできますか?

私は基本的に、特定の検証規則が破られたときにスタイルを提供するために、添付プロパティでコンバーターを使用したいと考えています。私は、次のようなマークアップを使用しています:

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

をしかし、これを実行すると、私は以下の取得:

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')

私はDataTrigger結合パスに「テキスト」に変更した場合、私は得ることはありませんデータバインディングエラー(もちろん、私が求めている動作を提供しません)。

答えて

27

あなたは括弧内のプロパティをラップする必要があります。

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

これはhttp://msdn.microsoft.com/en-us/library/ms752300.aspx#Path_Syntax –

+0

@MでMSDNに記載されています。 Dudleyリンクはもう働いていません! –

+2

新しいリンク:https://msdn.microsoft.com/library/ms752300%28v=vs.100%29.aspx#Path_Syntax –

関連する問題