目前,我对在项目之间剪切和粘贴转换器感到有点厌倦。
有没有什么方法可以使用单个Converters对象,该对象将converters作为字段/属性?
例如,像这样:
<Application.Resources>
<sharedLib:Converters
x:Key="Converters" />
</Application.Resources>
<TextBlock Text="{Binding Target, Converter={StaticResource Converters.MakeAllCaps}}" />如果没有,那么有没有人对如何批量导入转换器有任何建议?
发布于 2012-02-21 20:40:29
您可以在资源字典中定义所有转换器,如下所示:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:loc="...">
<loc:BooleanToVisibilityConverter x:Key="BooleanToVisibility" />
<loc:MakeAllCapsConverter x:Key="MakeAllCaps" />
<!-- Define all the common converters here -->
</ResourceDictionary>现在,您可以通过MergedDictionaries将此资源字典导入到任何位置,如下所示:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Converters.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
<TextBlock Text="{Binding Target, Converter={StaticResource MakeAllCaps}}" />https://stackoverflow.com/questions/9377460
复制相似问题