[英]Provide value on 'System.Windows.StaticResourceExtension
Inside a XAML
Page I'm trying to use an IValueConverter
, it's throwing an error.在XAML
页面中,我正在尝试使用IValueConverter
,它会引发错误。
IValueConverter
is in another assembly, I have added a reference IValueConverter
在另一个程序集中,我添加了一个引用At the top of my page I have this:在我的页面顶部,我有这个:
xmlns:converters="clr-namespace:Converters;assembly=Converters"
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/DialogStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
<converters:NoWhiteSpaceConverter x:Key="NoWhiteSpaceConverter" />
</ResourceDictionary>
</Page.Resources>
Then I try to use it later on like this:然后我稍后尝试像这样使用它:
<TextBox Text="{Binding SomeText, Converter={StaticResource NoWhiteSpaceConverter}}" />
Can anyone see what the problem is?任何人都可以看到问题是什么吗?
Make sure that the resources are defined before the usage (in Xaml parsing order). 确保在使用之前定义资源(在Xaml解析顺序中)。 The easiest way is to place it into App.xaml 最简单的方法是将其放入App.xaml
See also here for a similar issue: http://www.paulkiddie.com/2011/10/the-importance-of-the-position-of-window-resources-element-in-wpf-xaml-markup/ 有关类似问题,请参见此处: http : //www.paulkiddie.com/2011/10/the-importance-of-the-position-of-window-resources-element-in-wpf-xaml-markup/
In my case the resource was correctly defined before it is used but there was a wrong reference to a converter.在我的例子中,资源在使用之前被正确定义,但是对转换器的引用是错误的。
The problematic line was有问题的行是
...{Binding MyProperty, Converter={StaticResource local:MyConverter}}
and it should be without the namespace alias它应该没有名称空间别名
...{Binding MyProperty, Converter={StaticResource MyConverter}}
where local
is a namespace alias containig the converter class and MyConverter
is the key defined in a resource in the XAML.其中local
是包含转换器 class 的命名空间别名, MyConverter
是 XAML 中资源中定义的键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.