Подтвердить что ты не робот

Добавить брешь в подсказке

¿Как добавить разделительную линию в текст внутри всплывающей подсказки в 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>

Но не работает:

4b9b3361

Ответ 1

<Label>
  <Label.ToolTip> 
     <TextBlock>
          Lorem ipsum dolor sit amet,
          <LineBreak /> 
          consectetur adipiscing elit. 
      </TextBlock> 
  </Label.ToolTip> 
</Label>
  ....

Ответ 2

Another approach that я find useful is to embed "&#x0a;" in the tooltip. The Tooltip will then have a Linebreak at this point. For example

ToolTip="Host name or IP address of the server. Click the &#x0a;Find Server button to help obtain the correct entry."

Это позволяет код xaml быть более кратким, но, возможно, менее читаемым. Подробнее в Новая строка в атрибуте string.

Ответ 3

Более компактный:

<Label TooTip="Line1 &#10; Line2" />

Ответ 4

Оберните свои элементы в StackPanel, которые будут складывать их поверх других.

Теперь у вас нет компиляции, потому что ToolTips может иметь только один дочерний объект, и вы пытаетесь добавить 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>

Ответ 5

Вы можете сделать это:

<Label>
<Label.ToolTip>
    <TextBlock>  
      Line1
      <LineBreak/>
     Line2
  </TextBlock>
</Label.ToolTip>
</Label>

Ответ 6

Выше ответы приведены только для кода xaml. Если вы хотите добавить новую строку в код CS, используйте "Environment.Newline"

label1.ToolTip="Line1" + Environment.NewLine + "Line2";

Ответ 7

Существует вариант подхода к линии:

<Label.ToolTip>
    <TextBlock>
        <Run Text="Line1"/>
        <LineBreak/>
        <Run Text="Line2"/>
    </TextBlock>
</Label.ToolTip>

Преимущество этого заключается в том, что каждая строка может иметь свой собственный стиль.