Odeslat dotazOdeslat dotaz
 

OdpovědětHow do I get my label to word wrap?

  • 4. listopadu 2009 16:27B. Clay Shannon Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     

    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

Odpovědi

  • 4. listopadu 2009 17:07B. Clay Shannon Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     Odpovědět
    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

Všechny reakce

  • 4. listopadu 2009 16:42wjousts Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     
    Put a TextBlock inside your label with TextWrapping set to Wrap
  • 4. listopadu 2009 17:00B. Clay Shannon Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     

    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
  • 4. listopadu 2009 17:07B. Clay Shannon Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     Odpovědět
    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
  • 4. listopadu 2009 18:00wjousts Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     

    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.