Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use a converter inside a ResourceDictionary

I have a converter thats works great when I use it as StaticResource on my Window as follows

<UserControl.Resources>
           <local:ValidationErrorConverter x:Key="validationErrorConverter"/>       
</UserControl.Resources>

I have a ResourceDictionary that defines my controls ControlTemplates and Styles , I couldn't figure out where to reference my converter as a StaticResource to be able to use it on my styles as follows

<Style.Triggers>
        <Trigger Property="Validation.HasError" Value="true">
            <Setter Property="ToolTip" Value="{Binding 
RelativeSource={RelativeSource Self}, 
Path=(Validation.Errors).CurrentItem, 
Converter={StaticResource HERE??}}"/>
        </Trigger>
    </Style.Triggers>
like image 384
Musaab Avatar asked Aug 07 '11 08:08

Musaab


1 Answers

Just create a new one, if the converter is needed for a Style just use Style.Resources for it. Or you could use element syntax:

<Setter.Value>
    <Binding Path="(Validation.Errors).CurrentItem"
             RelativeSource="{RelativeSource Self}">
        <Binding.Converter>
            <local:ValidationErrorConverter />
       </Binding.Converter>
    </Binding>
</Setter.Value>
like image 100
H.B. Avatar answered Nov 15 '22 20:11

H.B.