wpf 添加转换器声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16538104/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding Converter declaration
提问by Svetlana Krupalnik
I try to insert an Imageto my GUIapplication by means of a Bindingand a Converter. I create an instance of a value converter in the resources of my MainWindow:
我尝试通过 a和 a将 a插入Image到我的GUI应用程序中。我在我的资源中创建了一个值转换器的实例:BindingConverterMainWindow
"xmlns:my1="clr-namespace:MyApp"
<Window.Resources>
<ResourceDictionary x:Key="Resc">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="StylesDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<my1:DirectionToImageConverter x:Key="DirectionToImageConverter"/>
</Window.Resources>
However, when I try to run the application I get the following exception:
但是,当我尝试运行该应用程序时,出现以下异常:
''Resources' property has already been set on 'MainWindow'.' Line number '16' and
line position '11'.
''Resources' 属性已在 'MainWindow' 上设置。行号“16”和
行位置“11”。
Please help. Thanks a lot in advance.
请帮忙。非常感谢。
回答by Max
You need to put your converter in the resource dictonary, see this question.
您需要将转换器放在资源字典中,请参阅此问题。
<Window.Resources>
<ResourceDictionary x:Key="Resc">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="StylesDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
<my1:DirectionToImageConverter x:Key="DirectionToImageConverter"/>
</ResourceDictionary>
</Window.Resources>

