views:

332

answers:

1

Dear all,

is it possible for a WPF Label to split itself automatically into several lines? In my following example, the text is cropped at the right.

<Window x:Class="..." xmlns="..." xmlns:x="..." Height="300" Width="300">
    <Grid>
        <Label>
            `_Twas brillig, and the slithy toves did gyre and gimble in the wabe:
            all mimsy were the borogoves, and the mome raths outgrabe.</Label>
    </Grid>
</Window>

Am I doing something wrong?

Taking other controls is unfortunately not a good option, since I need support of access keys.

Replacing the Label with a TextBlock (having TextWrapping="Wrap"), and adjusting its control template to recognize access keys would be perhaps a solution, but isn't it an overkill?

Edit: having a non-standard style for label will break skinning, so I would like to avoid it if possible.

+2  A: 

Using both Label and TextBlock together seems to be the correct answer. There's a howto located here that demonstrates this exact issue.

Specifically, in their example, to get wrapping text and an access key:

<Label Width="200" HorizontalAlignment="Left"
       Target="{Binding ElementName=textBox1}">
  <AccessText TextWrapping="WrapWithOverflow">
    _Another long piece of text that requires text wrapping
    goes here.
  </AccessText>
</Label>
Ben Von Handorf
Thanks a lot, this must be what I needed. Let me check...
Vlad
Indeed, it worked! :-)
Vlad
@Ben: In your answer, s/TextBlock/AccessText/ :-)
Vlad
@Vlad, I suspected that was true, but I did copy-paste it from MSDN. I guess the real answer is to never trust MSDN. :)
Ben Von Handorf
@Ben: Yes, it's always better to try first. :)
Vlad