【发布时间】:2013-07-09 13:05:10
【问题描述】:
我有一个带有多个按钮的界面。我想根据“复杂”条件启用或禁用这些按钮。为了避免代码重复,我将此 MultiBinding 声明为应用程序资源:
<MultiBinding x:Key="MyMultiBinding" Converter="{StaticResource ResourceKey=MyConverter}">
<Binding Path="IsConnected" />
<Binding Path="IsOpened" />
</MultiBinding>
这是我声明按钮的方式:
<Button Name="MyButton" Content="Click me!" IsEnabled="{StaticResource ResourceKey=MyMultiBinding}" />
在运行时,我收到以下错误:“Set property IsEnabled throw an exception... MultiBinding is not a valid value for property IsEnabled”。
我不明白为什么这不起作用。您能否指出正确的方法来做到这一点?谢谢。
【问题讨论】:
-
不确定是否允许
MultiBinding作为资源。我什至无法编译A 'MultiBinding' cannot be set on the 'Value' property of type 'DictionaryEntry'. A 'MultiBinding' can only be set on a DependencyProperty of a DependencyObject.最简单的方法似乎是将其包装成Style并在那里进行属性绑定并将Style应用到您的控件,或者使用特定键或使其隐式. Example -
MultiBinding 被允许作为资源。我可以毫无问题地在 Application.Resources 中添加一个。无论如何,我将它包装成一个 Style 并且它正在工作。谢谢!
标签: wpf xaml binding properties staticresource