Fazer uma PerguntaFazer uma Pergunta
 

RespondidoHow do I get my label to word wrap?

  • quarta-feira, 4 de novembro de 2009 16:27B. Clay Shannon Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    Here's my xaml:

    <Label Name="lblQuestion" Grid.Row="2" FontSize="28" Foreground="Navy" HorizontalAlignment="Stretch" >Some Question?</Label>

    The HorizontalAlignment="Stretch" doesn't seem to do diddly squat -- how can I get the label's content to word wrap?


    Writer / Photographer - http://www.feedbooks.com/userbook/3631

Respostas

  • quarta-feira, 4 de novembro de 2009 17:07B. Clay Shannon Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    I simply replaced the label with a TextBlock, and now it works fine:

     

     

     

    <TextBlock Name="tbQuestion" Grid.Row="2" FontSize="28" TextWrapping="Wrap" Foreground="Navy" HorizontalAlignment="Stretch" >Some Question?</TextBlock>


    Writer / Photographer - http://www.feedbooks.com/userbook/3631
    • Marcado como RespostaB. Clay Shannon quarta-feira, 4 de novembro de 2009 17:07
    •  

Todas as Respostas

  • quarta-feira, 4 de novembro de 2009 16:42wjousts Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Put a TextBlock inside your label with TextWrapping set to Wrap
  • quarta-feira, 4 de novembro de 2009 17:00B. Clay Shannon Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    Putting a TextBlock inside the label:

    <Label Name="lblQuestion" Grid.Row="2" FontSize="28" Foreground="Navy" HorizontalAlignment="Stretch" >Some Question?
            <TextBlock TextWrapping="Wrap" Grid.Row="2"></TextBlock>
                </Label>

    ...won't compile.

    Putting a TextBlock around the Label:

            <TextBlock TextWrapping="Wrap" Grid.Row="2">
            <Label Name="lblQuestion" Grid.Row="2" FontSize="28" Foreground="Navy" HorizontalAlignment="Stretch" >Some Question?</Label>
            </TextBlock>

    ...did not work.


    Writer / Photographer - http://www.feedbooks.com/userbook/3631
  • quarta-feira, 4 de novembro de 2009 17:07B. Clay Shannon Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    I simply replaced the label with a TextBlock, and now it works fine:

     

     

     

    <TextBlock Name="tbQuestion" Grid.Row="2" FontSize="28" TextWrapping="Wrap" Foreground="Navy" HorizontalAlignment="Stretch" >Some Question?</TextBlock>


    Writer / Photographer - http://www.feedbooks.com/userbook/3631
    • Marcado como RespostaB. Clay Shannon quarta-feira, 4 de novembro de 2009 17:07
    •  
  • quarta-feira, 4 de novembro de 2009 18:00wjousts Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    Putting a TextBlock inside the label:

    <Label Name="lblQuestion" Grid.Row="2" FontSize="28" Foreground="Navy" HorizontalAlignment="Stretch" >Some Question?
            <TextBlock TextWrapping="Wrap" Grid.Row="2"></TextBlock>
                </Label>

    ...won't compile.

    Putting a TextBlock around the Label:

            <TextBlock TextWrapping="Wrap" Grid.Row="2">
            <Label Name="lblQuestion" Grid.Row="2" FontSize="28" Foreground="Navy" HorizontalAlignment="Stretch" >Some Question?</Label>
            </TextBlock>

    ...did not work.


    Writer / Photographer - http://www.feedbooks.com/userbook/3631
    No, you can't put text (which WPF will automatically convert to a TextBlock) plus another TextBlock as the child of a label. A Label can only have one child. Put the TextBlock inside the label and the text inside the TextBlock. Or just use the TextBlock by itself if you don't need the additional features of the label.