为什么MultiBinding与转换器不工作在工具提示? [英] Why does MultiBinding with a Converter not work within a ToolTip?

查看:199
本文介绍了为什么MultiBinding与转换器不工作在工具提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于相当复杂的WPF工具提示的一部分,我试图使用MultiBinding来生成基于两个属性的格式化文本。问题是,绑定的MultiConverter收到数组中的每个项目的 DependencyProperty.UnsetValue

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.

以下作品使用单个绑定

<ToolTipService.ToolTip>
  <StackPanel>
    <TextBlock>
      <TextBlock.Text>
        <Binding Path="Amt" Converter="{StaticResource singleValueConverter}"/>
      </TextBlock.Text>
    </TextBlock>        
  </StackPanel>
</ToolTipService.ToolTip>

这样做,使用 MultiBinding 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>

但是一个 MultiBinding 转换器不:

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?

推荐答案

罢工>尝试设置您的绑定模式=OneWay。

Try setting Mode="OneWay" on your binding.

此外,您是否检查了此问题和解决方案:
http://social.msdn.microsoft.com /论坛/ en-IE / wpf / thread / 15ada9c7-f781-42c5-be43-d07eb1f90ed4

Also, have you checked this problem and solution: http://social.msdn.microsoft.com/Forums/en-IE/wpf/thread/15ada9c7-f781-42c5-be43-d07eb1f90ed4


错误是
工具提示尚未加载,所以
DependencyProperty.GetValue返回
DependencyProperty.UnsetValue。你
应该添加一些代码来测试是
的值是Dependency.UnsetValue。
以下代码显示了如何执行此操作。

The reason of this error is the tooltips have not been loaded, so DependencyProperty.GetValue returns DependencyProperty.UnsetValue. You should add some code to test that is value is Dependency.UnsetValue. The following code shows how to do this.



public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
    if (values[0] == DependencyProperty.UnsetValue || values[1] == DependencyProperty.UnsetValue) 
        return "";
    [...]
}

这篇关于为什么MultiBinding与转换器不工作在工具提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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