在"System.Windows.StaticResourceExtension"上提供值 [英] Provide value on 'System.Windows.StaticResourceExtension

查看:50
本文介绍了在"System.Windows.StaticResourceExtension"上提供值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XAML 页面内,我正在尝试使用 IValueConverter ,它引发了错误.

Inside a XAML Page I'm trying to use an IValueConverter, it's throwing an error.

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

推荐答案

确保在使用之前(按Xaml解析顺序)定义了资源.最简单的方法是将其放入App.xaml

Make sure that the resources are defined before the usage (in Xaml parsing order). The easiest way is to place it into 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/

这篇关于在"System.Windows.StaticResourceExtension"上提供值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆