[英]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 当我在Window上将它用作StaticResource时,我有一个很好用的转换器,如下所示
<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 我有一个ResourceDictionary来定义我的控件ControlTemplates和Styles,我无法弄清楚在哪里引用我的转换器作为StaticResource,以便能够在我的样式上使用它如下
<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. 只需创建一个新的,如果Style需要转换器,只需使用
Style.Resources
。 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.