简体   繁体   English

在'System.Windows.StaticResourceExtension 上提供价值

[英]Provide value on 'System.Windows.StaticResourceExtension

Inside a XAML Page I'm trying to use an IValueConverter , it's throwing an error.XAML页面中,我正在尝试使用IValueConverter ,它会引发错误。

  • The IValueConverter is in another assembly, I have added a reference IValueConverter在另一个程序集中,我添加了一个引用
  • There are no design-time errors没有设计时错误
  • I have assigned the StaticResource with a ResourceKey我已经为 StaticResource 分配了 ResourceKey

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.

相关问题 在“ System.Windows.StaticResourceExtension”上提供值 - Provide value on 'System.Windows.StaticResourceExtension' System.Windows.StaticResourceExtension不能使用aplied属性 - System.Windows.StaticResourceExtension cannot aplied property 奇怪的XAML错误:“无法应用“ System.Windows.StaticResourceExtension” - Odd XAML Error: '“System.Windows.StaticResourceExtension” cannot be applied' Windows 7上的WPF:ValueConverter中的GetCultureInfo导致Provide Value上出现StaticResourceExtension异常 - WPF on Windows 7: GetCultureInfo in ValueConverter causing StaticResourceExtension exception on Provide Value 在“ System.Windows.Baml2006.TypeConverterMarkupExtension”上提供值引发异常 - Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception '在 'System.Windows.Baml2006.TypeConverterMarkupExtension' 上提供值引发异常。 - 'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' "Xaml 异常:“在 &#39;System.Windows.Markup.StaticResourceHolder&#39; 上提供值引发异常。”" - Xaml exception: "Provide value on 'System.Windows.Markup.StaticResourceHolder' threw an exception." 如何解决此错误:“在&#39;System.Windows.Baml2006.TypeConverterMarkupExtension&#39;上提供值” - How do I fix this error : 'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' &#39;为&#39;System.Windows.Baml2006.TypeConverterMarkupExtension&#39;提供价值,引发了一个异常。 行号&#39;49&#39;和行位置&#39;38&#39; - 'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '49' and line position '38' 获取 System.Windows.Forms.Timer 的值? - Get the value of a System.Windows.Forms.Timer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM