how to use a converter inside a ResourceDictionary

Musaab picture Musaab · Aug 7, 2011 · Viewed 10.8k times · Source

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>

Answer

H.B. picture H.B. · Aug 7, 2011

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>