# Other .NET Programming > Windows Presentation Foundation (WPF) & XAML forum >  WPF Button Content Multi-line

## MikeB

I have a button template. I want the button text to be multiline, but I have no idea how to set this.

I know I can set this in the xaml where I create the button by adding a text block and using <LineBreak/> but this overrides the TextBlock used by the button template.

E.G: The following would work, but the text block defined replaces the text block used by the template. This is no good.


```
<Button Template="{StaticResource MenuButtonTemplate}">
     <TextBlock>
          Project<LineBreak/>Management
     </TextBlock>
</Button>
```

E.G: The following is my button template:


```
  <ControlTemplate x:Key="MenuButtonTemplate" TargetType="{x:Type Button}">
        <Border Name="MenuButtonBorder" 
                BorderBrush="Black" 
                BorderThickness="1"
                CornerRadius="3"
                Background="Transparent"
                TextBlock.Foreground="White"
                TextBlock.FontSize="12"
                TextBlock.TextAlignment="Center"
                Width="80"
                Margin="3,3,3,3">
            <Grid>
                <Rectangle Name="MenuButtonFocusCue" 
                           Visibility="Hidden"
                           Stroke="LightSteelBlue"
                           StrokeThickness="1"
                           SnapsToDevicePixels="True">
                </Rectangle>
                <ContentPresenter RecognizesAccessKey="True"
                                  Margin="2,2,2,2"
                                  VerticalAlignment="Center">
                </ContentPresenter>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="MenuButtonBorder"
                        Property="Background"
                        Value="Transparent"/>
                <Setter TargetName="MenuButtonBorder"
                        Property="TextBlock.Foreground"
                        Value="Yellow"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter TargetName="MenuButtonBorder"
                        Property="Background"
                        Value="Transparent"/>
                <Setter TargetName="MenuButtonBorder"
                        Property="TextBlock.Foreground"
                        Value="Yellow"/>
            </Trigger>
            <Trigger Property="IsKeyboardFocused" Value="True">
                <Setter TargetName="MenuButtonFocusCue" 
                        Property="Visibility"
                        Value="Visible"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
```

Any suggestions would be appreciated.

Mike B

----------


## Arjay

I'd start my investigation looking over these solutions: found here.

----------


## MikeB

> I'd start my investigation looking over these solutions: found here.


Arjay

That was unexpected from you and uncool...... Anyway, I did search google first, I also looked through my Pro WPF in C# 2008 book and I could not find the answer.

I want the text block in a button template to be set to multi-line. I did try text wrap, but when I specify TextBlock.TextWrapping, I get an error saying property cannot be found.

If you have any valid suggestions, I wouldn't mind reading them.

Thanks

Mike B

----------


## Arjay

You know we answer a lot of questions around here so it's pretty hard to keep track of those too busy to look things up for themselves.

So help us out here.  If you've looked in google, how about stating why the solutions found in a google search "WPF text multiline" aren't adequate.

----------


## MikeB

> You know we answer a lot of questions around here so it's pretty hard to keep track of those too busy to look things up for themselves.
> 
> So help us out here.  If you've looked in google, how about stating why the solutions found in a google search "WPF text multiline" aren't adequate.


Arjay,

Creating multi-line text is not the problem. Creating multi-line button text is not the problem. The problem is creating a *button template*  in a resource file where the content presenter supports text wrapping. This I cannot find on google. In fact, if I type WPF Multiline button, this post is near the top....

Why should I have to add <LineBreak/> or create a new TextBlock for my buttons every time I use them simply to support text wrapping? I should just be able to add this to my Button Template and be done with it. This is my problem.

Mike B

----------


## MikeB

Alright, well, I thought I found the solution, but it doesn't work...... I should have searched for ContentPresenter then I would have known that this is actually a place holder for the content and for lack of a better description means "YOUR CONTENT GOES HERE!".

So, I added the TextBlock to my template and placed the ContentPresenter there, but......not wrapping.



```
<TextBlock TextAlignment="Center"
                           VerticalAlignment="Center"
                           Foreground="White"
                           FontSize="12"
                           TextWrapping="Wrap">
                    <ContentPresenter RecognizesAccessKey="True"/>
                </TextBlock>
```

Mike B

----------


## gurge60

I think that you can set the ContentPresenter's ContentTemplate like so:



```
<ContentPresenter RecognizesAccessKey="True"
          Margin="2,2,2,2"
          VerticalAlignment="Center">
    <ContentPresenter.ContentTemplate>
        <DataTemplate>
            <TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" Text="{Binding}" TextWrapping="Wrap" Height="Auto" Width="Auto" />
        </DataTemplate>
    </ContentPresenter.ContentTemplate>
</ContentPresenter>
```

----------


## andrw

I have another question about accessing TextBlock, which is inside a button template. 
there is a template in xaml:


```
<controltemplate x:key="buttempl1" targettype="{x:type button}">
  <border>
     <grid>
       <textblock name="tx1" text="asd"/>
     </grid>
  </border>
</controltemplate>
```

and the button


```
<button name="btn1" template="{dynamicresource buttempl1} />
```

How can I dynamically change tx1.Text in vb code for this button?

----------

