views:

181

answers:

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  A: 

This

<Style TargetType="TextBox">

should be:

<Style TargetType="{x:Type TextBox}">
Tony
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.
Dmitry
+1  A: 

Use

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

instead in style

Gal