相关疑难解决方法(0)

与StringFormat的WPF绑定在ToolTips上不起作用

下面的代码有一个简单的绑定,它使用完全相同的Binding表示法将名为MyTextBlock的TextBlock的Text绑定到TextBox的Text和ToolTip属性:

<StackPanel>
    <TextBlock x:Name="MyTextBlock">Foo Bar</TextBlock>
    <TextBox    Text="{Binding ElementName=MyTextBlock, Path=Text, StringFormat='It is: \{0\}'}"
             ToolTip="{Binding ElementName=MyTextBlock, Path=Text, StringFormat='It is: \{0\}'}" />
</StackPanel>
Run Code Online (Sandbox Code Playgroud)

绑定还使用.NET 3.5 SP1引入StringFormat属性,该属性对于上面的Text属性工作正常但似乎在工具提示中被破坏.预期的结果是"它是:Foo Bar",但是当您将鼠标悬停在TextBox上时,ToolTip仅显示绑定值,而不是字符串格式化的值.有任何想法吗?

wpf binding

83
推荐指数
4
解决办法
3万
查看次数

标签 统计

binding ×1

wpf ×1