[英]WPF - ToolTip with multibinding
I want to make a tooltip with multibinding inside a text block, but whatever I try it doesn't work. 我想在文本块中创建一个带有多绑定的工具提示,但无论我尝试它都不起作用。
Here is what I've tried so far: 这是我到目前为止所尝试的:
<TextBlock Text="{Binding Description, StringFormat='Description : {0}{}'}">
<ToolTipService.ToolTip>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="Description : {0}{1}{}">
<Binding Path="FirstDescription" />
<Binding Path="SecondDescription" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</ToolTipService.ToolTip>
</TextBlock>
But when I try it, what I see on the tooltip is : System.Windows.Controls.TextBlock. 但是当我尝试它时,我在工具提示上看到的是:System.Windows.Controls.TextBlock。
when i try it without tooltipservice, and only tooltip, like this : 当我尝试没有tooltipservice,只有工具提示,像这样:
<TextBlock Text="{Binding Description, StringFormat='Description : {0}{}'}">
<ToolTip>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="Description : {0}{1}{}">
<Binding Path="FirstDescription" />
<Binding Path="SecondDescription" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</ToolTip>
</TextBlock>
The screen just get stuck. 屏幕刚刚卡住了。
I dont't know wich VS version you are using but: 我不知道你使用的VS版本但是:
<TextBlock Text="{Binding Description, StringFormat="Description : {0}{}"}">
does not even compile for me. 甚至不为我编译。
Just remove the " and the empty brackets like that: 只需删除“和那样的空括号:
<TextBlock Text="{Binding Description, StringFormat=Description : {0}">
You could also write it like this if you want the ": 你也可以这样写,如果你想要“:
<TextBlock>
<TextBlock.Text>
<Binding Path="Description" StringFormat="Description : {0}" />
</TextBlock.Text>
<ToolTipService.ToolTip>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="Description : {0}{1}">
<Binding Path="FirstDescription" />
<Binding Path="SecondDescription" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</ToolTipService.ToolTip>
</TextBlock>
Just delete empty brackets. 只需删除空括号即可。 Next code work as expected: 下一代码按预期工作:
<TextBlock Text="{Binding Description, StringFormat='Description : {0}'}">
<ToolTipService.ToolTip>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="Description : {0}{1}">
<Binding Path="FirstDescription" />
<Binding Path="SecondDescription" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</ToolTipService.ToolTip>
</TextBlock>
If the StringFormat starts with a left brace { the XAML parser require you to escape it using a pair of braces {}. 如果StringFormat以左括号开头{XAML解析器要求您使用一对大括号{}来转义它。 Otherwise the parser gets confused because braces also are used in the syntax of markup extensions. 否则解析器会感到困惑,因为大括号也用在标记扩展的语法中。
Details are found in the XAML documentation for {} Escape Sequence / Markup Extension . 有关{}转义序列/标记扩展的XAML文档中的详细信息。
Also, you can't use double quotes with inline binding but single quotes is available. 此外,您不能使用内联绑定的双引号,但可以使用单引号。
I have tried the following code and that worked perfectly: 我尝试了以下代码并且完美地工作:
<TextBlock Margin="20" Foreground="Black" FontSize="20" FontFamily="Century Gothic" Text="{Binding Name1}">
<TextBlock.ToolTip>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="MultiBinded Tooltip : {0}{1}">
<Binding Path="Name1"/>
<Binding Path="Name2"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</TextBlock.ToolTip>
</TextBlock>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.