为什么带有转换器的多重绑定在工具提示中不起作用?
对于相当复杂的 WPF 工具提示的一部分,我尝试使用 MultiBinding 来生成基于两个属性的格式化文本。问题是,绑定的 MultiConverter 接收其 values
数组中每个项目的 DependencyProperty.UnsetValue
。
使用单个 Binding
可以实现以下效果:
<ToolTipService.ToolTip>
<StackPanel>
<TextBlock>
<TextBlock.Text>
<Binding Path="Amt" Converter="{StaticResource singleValueConverter}"/>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</ToolTipService.ToolTip>
使用带有 StringFormat
的 MultiBinding
也是如此:
<ToolTipService.ToolTip>
<StackPanel>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat='{0:C} in {1}'>
<Binding Path="Amt"/>
<Binding Path="Currency"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</ToolTipService.ToolTip>
但是 MultiBinding
与 Converter
则不会:
<ToolTipService.ToolTip>
<StackPanel>
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource multiValueConverter}">
<Binding Path="Amt"/>
<Binding Path="Currency"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</ToolTipService.ToolTip>
最后一个示例中的绑定不会接收任何值。工具提示之外的情况并非如此 - 在这种特定情况下发生了什么导致绑定失败?
For part of a fairly-complex WPF ToolTip, I'm attempting to use a MultiBinding to produce formatted text based on two properties. The problem is, the binding's MultiConverter receives DependencyProperty.UnsetValue
for each item in its values
array.
The following works, using a single Binding
:
<ToolTipService.ToolTip>
<StackPanel>
<TextBlock>
<TextBlock.Text>
<Binding Path="Amt" Converter="{StaticResource singleValueConverter}"/>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</ToolTipService.ToolTip>
And so does this, using a MultiBinding
with StringFormat
:
<ToolTipService.ToolTip>
<StackPanel>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat='{0:C} in {1}'>
<Binding Path="Amt"/>
<Binding Path="Currency"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</ToolTipService.ToolTip>
But a MultiBinding
with a Converter
does not:
<ToolTipService.ToolTip>
<StackPanel>
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource multiValueConverter}">
<Binding Path="Amt"/>
<Binding Path="Currency"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</ToolTipService.ToolTip>
The bindings in the last example don't receive any value. This isn't the case outside of a ToolTip - what is going on such that binding fails in this specific case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在绑定上设置 Mode="OneWay"。另外,您是否检查过此问题和解决方案:
http://social.msdn.microsoft.com/Forums/en-IE/wpf/thread/15ada9c7-f781-42c5-be43-d07eb1f90ed4
Try setting Mode="OneWay" on your binding.Also, have you checked this problem and solution:
http://social.msdn.microsoft.com/Forums/en-IE/wpf/thread/15ada9c7-f781-42c5-be43-d07eb1f90ed4
试试这个:
Try this: