da1th1
da1th1

Reputation: 55

TextWrapping on Windows Phone 7 Button

I am having a problem trying to get text to wrap on a windows phone button. The problem is that the text justs gets cut off! I have tried almost everything but the problem persists. I have searched the problem but I havent found a solution that has worked.

This is my code:

    <Button Height="127" HorizontalAlignment="Left" Margin="12,548,0,0" Name="button1" VerticalAlignment="Top" Width="224" Click="button1_Click" Foreground="#FFEBF362" FontFamily="Segoe WP" BorderBrush="#FFEDF0F1" Background="#FF1BA1E2" >
        <Button.Content>
            <TextBlock Text="Button" TextWrapping="Wrap" Height="84"  TextAlignment="Center" VerticalAlignment="Stretch" HorizontalAlignment="Center" Padding="0" FontSize="36" Width="186" FontFamily="Segoe WP" />
        </Button.Content>
    </Button>

Upvotes: 1

Views: 1138

Answers (2)

Duncan Matheson
Duncan Matheson

Reputation: 1726

Instead of setting the content like you have, you could use a ContentTemplate:

<Button Name="button1" Content="Hello Cakes">
    <Button.ContentTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding}" TextWrapping="Wrap"/>
        </DataTemplate>
    </Button.ContentTemplate>
</Button>

This would then work if you wanted to set button1.Content from code. In addition, you could pull out the DataTemplate into a resource and reuse it between buttons.

This is also much better practice.

Upvotes: 5

Iris Classon
Iris Classon

Reputation: 5842

I tried the code and it seems to work, any chance you have the button nested in an element that has a constrained size? You've set some sizes as well, so there will be some limits to how much text you can see with the fontsize and font family. With the text 'Button Button Button Button' only the two first button will show, the second one on a new line, with the same font and fontsize (when I tried the code- I only changed one of the margins from 499 to 99 for the screen shot)

enter image description here

Maybe if you share some more code we can help you find the culprit, but check the sizes, margins, and elements. It is so easy to miss something!

Upvotes: 2

Related Questions