¿如何在XAML的工具提示中为文本添加断行线?
我尝试这个:
<Label Name="label4" UseLayoutRounding="False" Focusable="False" AllowDrop="False" Foreground="Black" Margin="6,44,132.027,76" ToolTipService.ShowDuration="12000">
<Label.ToolTip>
<ToolTip>
<TextBlock>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </TextBlock>
<TextBlock>Suspendisse eget urna eget elit ullamcorper tincidunt. Sed nec arcu sed ante sodales </TextBlock>
<TextBlock>Pellentesque elit libero, semper ac tincidunt vitae, euismod at ligula.</TextBlock>
</ToolTip>
</Label.ToolTip>
<Label.Content>
<TextBlock TextAlignment="Right" TextWrapping="Wrap" Height="19" Width="108" >Lorem Ipsum</TextBlock>
</Label.Content>
</Label>
Run Code Online (Sandbox Code Playgroud)
但不起作用:
小智 95
我觉得有用的另一种方法是嵌入
工具提示中.此时工具提示将有一个Linebreak.例如
ToolTip="Host name or IP address of the server. Click the 
Find Server button to help obtain the correct entry."
Run Code Online (Sandbox Code Playgroud)
这允许xaml代码更简洁,但可能不太可读.Newline in string属性中的更多细节.
HCL*_*HCL 69
<Label>
<Label.ToolTip>
<TextBlock>
Lorem ipsum dolor sit amet,
<LineBreak />
consectetur adipiscing elit.
</TextBlock>
</Label.ToolTip>
</Label>
....
Run Code Online (Sandbox Code Playgroud)
Rac*_*hel 13
将您的物品包裹在StackPanel中,StackPanel将它们叠加在另一个上面
您现在拥有的内容将无法编译,因为ToolTips只能有1个子对象,并且您尝试添加3
<Label Name="label4" UseLayoutRounding="False" Focusable="False" AllowDrop="False" Foreground="Black" Margin="6,44,132.027,76" ToolTipService.ShowDuration="12000">
<Label.ToolTip>
<StackPanel>
<TextBlock>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </TextBlock>
<TextBlock>Suspendisse eget urna eget elit ullamcorper tincidunt. Sed nec arcu sed ante sodales </TextBlock>
<TextBlock>Pellentesque elit libero, semper ac tincidunt vitae, euismod at ligula.</TextBlock>
</StackPanel>
</Label.ToolTip>
<Label.Content>
<TextBlock TextAlignment="Right" TextWrapping="Wrap" Height="19" Width="108" >Lorem Ipsum</TextBlock>
</Label.Content>
</Label>
Run Code Online (Sandbox Code Playgroud)
以上答案仅适用于xaml代码.如果要在CS代码中添加新行,请使用"Environment.Newline"
label1.ToolTip="Line1" + Environment.NewLine + "Line2";
Run Code Online (Sandbox Code Playgroud)