---
title: "WPF button textwrap style"  
description: "WPF button textwrap style"  
author: "Anonymous User"  
published: 2013-09-21  
updated: 2013-09-21  
canonical: https://www.mindstick.com/forum/1466/wpf-button-textwrap-style  
category: "wpf"  
tags: ["wpf"]  
reading_time: 2 minutes  

---

# WPF button textwrap style

How do I change the [default](https://www.mindstick.com/interview/12771/what-is-the-importance-of-default-resources) textwrapping style of a [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) in WPF?

The obvious solution of:

```
<Style x:Key="MyButtonStyle" TargetType="{x:Type Button}">    <Setter Property="TextWrapping" Value="Wrap"></Setter></Style>
```

doesn't work, because Textwrapping isn't a settable [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) here, apparently.

If I try:

```
<Style x:Key="MyButtonStyle" TargetType="{x:Type Button}">    <Setter Property="Template">        <Setter.Value>            <ControlTemplate TargetType="{x:Type Button}">                <TextBlock Text="{Binding}" Foreground="White" FontSize="20" FontFamily="Global User Interface" TextWrapping="Wrap"/>            </ControlTemplate>        </Setter.Value>    </Setter></Style>
```

I just get a worthless [response](https://www.mindstick.com/forum/12719/how-to-make-response-write-display-special-character-like-lt-gt) from the [compiler](https://www.mindstick.com/articles/27/just-in-time-compiler):

Error 5 After a 'SetterBaseCollection' is in use (sealed), it cannot be modified.

Removing the ControlTemplate tag keeps the error.

The following attempt yields a different error:

```
    <Setter Property="TextBlock">        <TextBlock Text="{Binding}" Foreground="White" FontSize="20" FontFamily="Global User Interface" TextWrapping="Wrap"/>    </Setter>
```

Error 5 The type 'Setter' does not [support](https://yourviews.mindstick.com/view/286/modi-support-for-sportsperson) [direct](https://yourviews.mindstick.com/view/86744/elon-musk-launch-its-first-direct-to-cell-starlink-satellites) content.

I see that I can set the textwrapping for each button individually, but that's pretty asinine. How can I do it as a style? What are the magic words?

And for [future](https://yourviews.mindstick.com/audio/1195/ayurveda-ancient-wisdom-for-modern-wellness-and-future-health) [reference](https://www.mindstick.com/forum/774/reference-what-does-this-error-mean-in-php), where can I find a list of these magic words, so I can just do this on my own? The MSDN entry is pretty useless when I try to find out about which [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties) can be set by the setter.

## Replies

### Reply by Sumit Kesarwani

Hi John,\

Your second version should work, and does for me, with the caveat that you need to change the TextBlock Text binding:

```
<!-- in Window.Resources --><Style x:Key="fie" TargetType="Button">  <Setter
Property="Template">   
<Setter.Value>     
<ControlTemplate TargetType="{x:Type Button}">        <TextBlock Text="{TemplateBinding Content}" FontSize="20"
TextWrapping="Wrap"/>     
</ControlTemplate>   
</Setter.Value>  </Setter></Style><!-- then -->
```

<Button Style="{StaticResource fie}">verylongcaptiongoeshereandwraps/Button>

Note this completely replaces the button style (i.e. you will need to create your own button chrome if you want it).

Regarding your second question, all writeable dependency properties can be set using a Setter. The reason you were unable to set TextWrapping on a Button via a style is that Button does not have a TextWrapping dependency property (or indeed any TextWrapping property). There are no "magic words," just the names of dependency properties.


---

Original Source: https://www.mindstick.com/forum/1466/wpf-button-textwrap-style

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
