样式未应用于WPF中的文本框
样式未应用于WPF中的文本框,wpf,textbox,wpf-controls,styles,Wpf,Textbox,Wpf Controls,Styles,HorizontalContentAlignment未应用于文本框 以下是样式定义: <Style TargetType="TextBox"> <Setter Property="HorizontalContentAlignment" Value="Center"/> </Style> 这是文本框的定义 <DockPanel LastChildFill="True"> <TabControl DockPanel
HorizontalContentAlignment
未应用于文本框
以下是样式定义:
<Style TargetType="TextBox">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
这是文本框的定义
<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>
以下是完整的示例:
<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>
这个
应该是:
<Style TargetType="{x:Type TextBox}">
使用
相反,在风格上谢谢你的回答,我以前试过,也不起作用。另外,我已经在文章中添加了完整的源代码。对于文本框,其他属性也可以很好地工作。
<Style TargetType="{x:Type TextBox}">