wpf 在“System.Windows.StaticResourceExtension”上提供值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13861866/
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
Provide value on 'System.Windows.StaticResourceExtension
提问by Drahcir
Inside a XAMLPage I'm trying to use an IValueConverter, it's throwing an error.
在XAML我尝试使用的 Page 中IValueConverter,它抛出了一个错误。
- The
IValueConverteris in another assembly, I have added a reference - There are no design-time errors
- I have assigned the StaticResource with a ResourceKey
- 的
IValueConverter是在另一组件中,我已经添加了一个参考 - 没有设计时错误
- 我已经为 StaticResource 分配了一个 ResourceKey
At the top of my page I have this:
在我的页面顶部,我有这个:
xmlns:converters="clr-namespace:Converters;assembly=Converters"
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?
任何人都可以看到问题是什么?
回答by Sebastian
Make sure that the resources are defined before the usage (in Xaml parsing order). The easiest way is to place it into App.xaml
确保在使用之前定义资源(按 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/

