2

HorizontalContentAlignment is not applied to textbox....

Here is the style definition:

<Style TargetType="TextBox">
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
 </Style>

and here is the TextBox definition

<DockPanel LastChildFill="True">
    <TabControl DockPanel.Dock="Top" Name="tabControl1">
        <TabItem Header="TemplateItem">
            <DockPanel LastChildFill="True">
                <GroupBox Header="Salutation" DockPanel.Dock="Top">
                    <StackPanel Orientation="Horizontal" Margin="0, 4, 0, 0">
                        <TextBox Name="tbSalut" Width="300"/>
                        <TextBlock Text="->" Margin="4, 0, 4, 0"/>
                        <TextBox Name="tbSalutTransl" Width="371"/>
                    </StackPanel>

Here is the full example:

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">

    <Window.Resources>
        <Style TargetType="{x:Type TextBox}">
            <Setter Property="BorderThickness" Value="10,1,1,1"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
        </Style>

    </Window.Resources>

    <Grid>
        <TextBox Height="23" Margin="12,51,12,0" Name="textBox1" VerticalAlignment="Top" />
    </Grid>
</Window>

2 Answers 2

3

Use

<Setter Property="TextAlignment" Value="Center"/>

instead in style

Sign up to request clarification or add additional context in comments.

Comments

2

This

<Style TargetType="TextBox">

should be:

<Style TargetType="{x:Type TextBox}">

1 Comment

Thanks for the answer, I've tried it before, doesn't work either. Also, I have added the full source code to the post. Other properties work well for the TextBox.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.