对于相当复杂的 WPF 工具提示的一部分,我尝试使用 MultiBinding 来生成基于两个属性的格式化文本。问题是,绑定的 MultiConverter 接收DependencyProperty.UnsetValue
对于其中的每个项目values
array.
以下作品,使用单个Binding
:
<ToolTipService.ToolTip>
<StackPanel>
<TextBlock>
<TextBlock.Text>
<Binding Path="Amt" Converter="{StaticResource singleValueConverter}"/>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</ToolTipService.ToolTip>
这也是如此,使用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
才不是:
<ToolTipService.ToolTip>
<StackPanel>
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource multiValueConverter}">
<Binding Path="Amt"/>
<Binding Path="Currency"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</ToolTipService.ToolTip>
最后一个示例中的绑定不接收任何值。工具提示之外的情况并非如此 - 在这种特定情况下发生了什么导致绑定失败?
尝试在绑定上设置 Mode="OneWay"。
另外,您检查过这个问题和解决方案吗:http://social.msdn.microsoft.com/Forums/en-IE/wpf/thread/15ada9c7-f781-42c5-be43-d07eb1f90ed4 http://social.msdn.microsoft.com/Forums/en-IE/wpf/thread/15ada9c7-f781-42c5-be43-d07eb1f90ed4
这个错误的原因是
工具提示尚未加载,所以
DependencyProperty.GetValue 返回
DependencyProperty.UnsetValue。你
应该添加一些代码来测试
值为 Dependency.UnsetValue。这
下面的代码展示了如何做到这一点。
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values[0] == DependencyProperty.UnsetValue || values[1] == DependencyProperty.UnsetValue)
return "";
[...]
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)