views:

159

answers:

1

I would like to know how to translate the following code to codebehind instead of XAML:

<Style.Triggers>
    <Trigger Property="Validation.HasError" Value="true">
        <Setter Property="ToolTip"
          Value="{Binding RelativeSource={RelativeSource Self},
          Path=(Validation.Errors)[0].ErrorContent}"/>
    </Trigger>
</Style.Triggers>

The part I can't figure out is the Path portion. I have the following but it doesn't work:

new Trigger
{
    Property = Validation.HasErrorProperty,
    Value = true,
    Setters = 
    {
        new Setter
        {
            Property = Control.ToolTipProperty,
            // This part doesn't seem to work
            Value = new Binding("(Validation.Errors)[0].ErrorContent"){RelativeSource = RelativeSource.Self}
         }
     }
 }

Help?

A: 

How to Create a Binding in Code (MSDN).

compozer
My issue isn't how to create bindings in code in general...its how I can do it in this particular case. I can't figure out how to bind to the Validation Errors. Specific help for this case would be appreciated.
KrisTrip