求教!SL中TextBox文字对齐问题!一个登录窗口,用户名输入框用TextBox控件,密码输入用PasswordBox。但这两个
求教!SL中TextBox文字对齐问题!
一个登录窗口,用户名输入框用TextBox控件,密码输入用PasswordBox。但这两个控件我都增大了它们的高度,这样就出现了个问题,文字显示位置还是靠上,介个问题怎么解决呢?
[解决办法]
TextAlignment="Center"
另外建议楼主用Blend绘制silverlight界面,效果很好
[解决办法]
[解决办法] <Style TargetType="TextBox" x:Name="myTextBox">
<Setter Property="FontSize" Value="13"></Setter>
<Setter Property="Text" Value="http://"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Grid x:Name="RootElement">
<Border x:Name="Border" BorderThickness="1" CornerRadius="0" Background="White" BorderBrush="Silver">
<ScrollViewer x:Name="ContentElement" VerticalAlignment="Center" BorderThickness="0" IsTabStop="False"/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
想怎么对齐,改ScrollViewer 就可以了.
[解决办法] <Style TargetType="PasswordBox">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Background" Value="#FFFFFFFF" />
<Setter Property="Foreground" Value="#FF000000" />
<Setter Property="Padding" Value="2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="PasswordBox">
<Grid x:Name="RootElement">
<Border x:Name="Border" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="1" Opacity="1" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}">
<Border x:Name="MouseOverBorder" BorderThickness="1" BorderBrush="Transparent">
<Border x:Name="ContentElement" VerticalAlignment="Center" Margin="{TemplateBinding Padding}"/>
</Border>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>