你有一个转换器,可以在使用这个转化器的xaml文件引用:
XML
<myWaferRobot:WaferIntToVisibilityConverter x:Key="cvt1"></myWaferRobot:WaferIntToVisibilityConverter>
但是你有很多转换器,每个界面分别去挑选自己用到的显得太麻烦,可以新建一个xaml资源字典(右键项目-添加-资源字典),里面给多个转换器添加key值:
XML
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Laser.Convert">
<local:ExtOrIntToString x:Key="ExtOrInt2String" />
<local:BoolToLedStatus x:Key="Bool2Status" />
<local:BoolToLedStatusYellow x:Key="Bool2LedStatusYellow" />
</ResourceDictionary>
比如新建的这个xaml资源字典名称是A.xaml,在APP.xaml中这样引用:
XML
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Style.xaml" />
<ResourceDictionary Source="Convert/Converts.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
即可在整个项目中任何地方使用转换器。