Fabián Romo
Fabián Romo

Reputation: 329

Without border style doesn't place the text in the center of a WPF button

I have the following style that hides or makes invisible at the border of a button:

<Style x:Key="SinBorde" TargetType="{x:Type Button}" >
    <Setter Property="Template" >
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Border Background="Transparent">
                    <ContentPresenter/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

And the button looks like the one on the left of the next image, notice the button on the right that doesn't have that style applied and the text is in the middle of the button:

enter image description here

Any comments or suggestions how to center text are welcome

Upvotes: 0

Views: 30

Answers (1)

ASh
ASh

Reputation: 35681

default Button template sets alignment for content:

<Style x:Key="SinBorde" TargetType="{x:Type Button}" >
    <Setter Property="Template" >
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Border Background="Transparent">
                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                      VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Upvotes: 1

Related Questions