开发者

how to use a converter inside a ResourceDictionary

开发者 https://www.devze.com 2023-03-26 05:25 出处:网络
I have a converter thats works great when I use it as StaticResource on my Window as follows <UserControl.Resources>

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

<UserControl.Resources>
           <local:Vali开发者_运维知识库dationErrorConverter 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>


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号