使用 CommandParameters 和多重绑定?
是否可以在多重绑定中使用 CommandParameter="{Binding}"? 我正在尝试在数据网格中执行此操作。
<CheckBox.CommandParameter>
<MultiBinding Converter="{StaticResource CDetailConverter}">
<Binding Path ="IsChecked" ElementName="chkSelection"/>
<Binding ConverterParameter="{Binding}"/>
</MultiBinding>
</CheckBox.CommandParameter>
第二个 Binding 抛出错误。
Is it possible to use CommandParameter="{Binding}" in a multi binding?
I am trying to do this in a data grid.
<CheckBox.CommandParameter>
<MultiBinding Converter="{StaticResource CDetailConverter}">
<Binding Path ="IsChecked" ElementName="chkSelection"/>
<Binding ConverterParameter="{Binding}"/>
</MultiBinding>
</CheckBox.CommandParameter>
The second Binding throws an error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简而言之,答案是否定的。
在第二个内部
Binding
中,您已设置ConverterParameter
。这有几个问题:首先,
Binding
是它自己的类,与MultiBinding
分开,同时具有Converter
和ConverterParameter属性。此处您已设置
ConverterParameter
属性,但未设置Converter
属性。请记住,ConverterParameter
会传递到Binding
指定的转换器,无论它是否在MultiBinding
中使用。如果您要在此处添加一个Converter
,那么该转换器将被传递指定的ConverterParameter
。您可能想要做的是在外部
MultiBinding
上设置ConverterParameter
,它也具有此属性:如果您尝试这样做,您很快就会看到
ConverterParameter
code> 不能是Binding
表达式的目标,因为它不是DependencyProperty
。由于您无法绑定到 CommandParameter,典型的解决方法是修改您的 IMultiConverter 以接受附加值,并通过绑定表达式提供该值:
希望这会有所帮助!
In a nutshell, the answer is no.
In your second inner
Binding
you have setConverterParameter
. There are a couple of problems with this:First,
Binding
is its own class separate fromMultiBinding
with bothConverter
andConverterParameter
properties. Here you have set theConverterParameter
property without setting theConverter
property. Remember thatConverterParameter
is passed to theBinding's
specified converter regardless if it is used within aMultiBinding
or not. If you were to add aConverter
here, then the converter would be passed the specifiedConverterParameter
.What you probably meant to do was set the
ConverterParameter
on the outerMultiBinding
which also has this property:If you try this, you will quickly see that
ConverterParameter
can not be the target of aBinding
expression since it is not aDependencyProperty
.Since you can not bind to
CommandParameter
, the typical workaround is to modify yourIMultiConverter
to accept an additional value, and supply this value through a binding expression:Hope this helps!