在 Silverlight 4 中将 ConverterParameter 绑定到资源文件
我正在尝试创建一个通用转换器,它将从资源 resx 文件(应用程序必须可本地化)中获取字符串作为参数。
<TextBlock
ToolTipService.ToolTip="{Binding IsInUse, ConverterParameter={Binding Path=WhereUsedIndicatorTooltips, Source={StaticResource resource}}, Converter={StaticResource whereUsedIndicatorTooltipConverter}}" />
在 XAML 中,资源在此页面顶部声明为:
<UserControl.Resources>
<resources:myResource x:Key="resource" />
</UserControl.Resources>
在运行时,我收到此异常:
System.Windows.Markup.XamlParseException: 提供价值 “System.Windows.Data.Binding”引发了 例外。 [线路:47 位置:42] ---> System.InvalidOperationException:由于以下原因操作无效 对象的当前状态......
我从 这个 StackOverflow 问题中了解到ConverterParameter
不可绑定,也不是 DependencyObject
。除了将文本放入 XAML 之外,是否有解决此问题的方法?
I'm trying to create a common converter that will take in a string from a resource resx file (the app has to be localizable) as a parameter.
<TextBlock
ToolTipService.ToolTip="{Binding IsInUse, ConverterParameter={Binding Path=WhereUsedIndicatorTooltips, Source={StaticResource resource}}, Converter={StaticResource whereUsedIndicatorTooltipConverter}}" />
Where resource is declared at the top of this page in XAML as:
<UserControl.Resources>
<resources:myResource x:Key="resource" />
</UserControl.Resources>
At runtime I get this exception:
System.Windows.Markup.XamlParseException:
Provide value on
'System.Windows.Data.Binding' threw an
exception. [Line: 47 Position: 42]
---> System.InvalidOperationException: Operation is not valid due to the
current state of the object.....
I'm aware from this StackOverflow question that the ConverterParameter
is not bindable and is not a DependencyObject
. Is there a workaround to this problem, besides putting the text in the XAML?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从 Brandon Truong 找到了解决方案。这非常有效。
我将带有 DependencyProperty 转换器的 FrameworkElement 放入:
I found a solution from Brandon Truong. This works very well.
I put my FrameworkElement with DependencyProperty converter in:
我在这里遇到同样的错误,
**
我使用了 Converter Culture 属性 Binded!Opps!我不能这样做,因为属性 ConverterCulture 不是 DependencyProperty。如果属性不是 DependencyProperty 的实例,则无法对其使用绑定如果
您查看 VS2010 上的属性(F4)窗格,您会发现某些属性支持绑定,某些属性则不支持!因为您知道某些属性是只读的,
因此使用资源是解决该问题的合理方法 。 。
I got same error here ,
**
I used Converter Culture property Binded! Opps! I can't do that because the property ConverterCulture is not a DependencyProperty. If a property is not instance of DependencyProperty you cant use binding on it.
If you look at Property(F4) Pane on VS2010 you can see that some properties support Binding some properties does not! Some properties not seen there because some properties are read only as u know.
So using resource is a logical way to solve it.