先从 TextBox 控件 说起,TextBox控件是输入框,类似于html中的 <input type="text" name="XX" id="XX" />标签,
TextBox 控件 InputScope类中的 Names可以指定输入框输入内容,例如电话输入框 里面只有数字等,大家可以自己看提示 。
顺便一起说下 密码框,里面输入的密码不可见。用法和TextBox 基本一致。举一个文本框的文字排列,举一个数字输入,一个密码输入。
页面代码如下:
<Grid x:Name="ContentPanel"
Grid.Row="0"
Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="输入你想输入的东西" />
<TextBox Name="txtContent"
Grid.Row="1"
Height="300"
HorizontalScrollBarVisibility="Auto"
TextWrapping="Wrap"
VerticalScrollBarVisibility="Auto" />
<StackPanel Grid.Row="2" Orientation="Horizontal">
<RadioButton Checked="RadioButton_Checked">左对齐</RadioButton>
<RadioButton Checked="RadioButton_Checked_1">居中对齐</RadioButton>
<RadioButton Checked="RadioButton_Checked_2">右对齐</RadioButton>
</StackPanel>
<StackPanel Grid.Row="3">
<TextBlock Text="数字" />
<TextBox>
<TextBox.InputScope>
<InputScope>
<InputScopeName NameValue="Number" />
</InputScope>
</TextBox.InputScope>
</TextBox>
</StackPanel>
<StackPanel Grid.Row="4">
<TextBlock Text="密码" />
<PasswordBox />
</StackPanel>
</Grid>
点击按钮后代码如下:
private void RadioButton_Checked(object sender, RoutedEventArgs e)
{
this.txtContent.TextAlignment = TextAlignment.Left;
}
private void RadioButton_Checked_1(object sender, RoutedEventArgs e)
{
this.txtContent.TextAlignment = TextAlignment.Center;
}
private void RadioButton_Checked_2(object sender, RoutedEventArgs e)
{
this.txtContent.TextAlignment = TextAlignment.Right;
}
启动模拟器 效果如图
OK 基本上就这多。
源码下载地址:http://download.csdn.net/detail/gongkepop/6257821
(写的不好请见谅,有不对请留言告知我,免得误人子弟。)