1. 换行
<LineBreak />
3. 自动断字换行 (TextWrapping )
<LineBreak />
Code
<TextBlock Margin="10" Grid.Row="0" Grid.Column="3">
<Run FontFamily="Arial" FontSize="20">TextBlock</Run>
<LineBreak />
<Run FontFamily="Courier New" FontWeight="Bold" FontSize="14">using Inlines</Run>
</TextBlock>
2. Button 与 RepeatButton<TextBlock Margin="10" Grid.Row="0" Grid.Column="3">
<Run FontFamily="Arial" FontSize="20">TextBlock</Run>
<LineBreak />
<Run FontFamily="Courier New" FontWeight="Bold" FontSize="14">using Inlines</Run>
</TextBlock>
Code
//Xaml内容
<RepeatButton x:Name="rbutTest" Content="1" Grid.Column="0" Grid.Row="0"></RepeatButton>
<Button x:Name="btnText" Content="0" Grid.Column="1" Grid.Row="0"></Button>
//Cs内容
public RepeatButtonControl()
{
InitializeComponent();
this.rbutTest.Click +=new RoutedEventHandler(rbutTest_Click);
this.btnText.Click +=new RoutedEventHandler(btnText_Click);
}
private void rbutTest_Click(object sender, RoutedEventArgs e)
{
int num = Convert.ToInt32(rbutTest.Content);
rbutTest.Content = ((num + 1).ToString());
}
private void btnText_Click(object sender, RoutedEventArgs e)
{
int num = Convert.ToInt32(btnText.Content);
btnText.Content = ((num + 100).ToString());
}
// RepeatButton说明
// 表示从被按下到松开之前重复引发其单击事件的按钮。
// RepeatButton 控件包含用于指定单击重复之前的延迟以及两次单击之间的间隔的属性。
//Xaml内容
<RepeatButton x:Name="rbutTest" Content="1" Grid.Column="0" Grid.Row="0"></RepeatButton>
<Button x:Name="btnText" Content="0" Grid.Column="1" Grid.Row="0"></Button>
//Cs内容
public RepeatButtonControl()
{
InitializeComponent();
this.rbutTest.Click +=new RoutedEventHandler(rbutTest_Click);
this.btnText.Click +=new RoutedEventHandler(btnText_Click);
}
private void rbutTest_Click(object sender, RoutedEventArgs e)
{
int num = Convert.ToInt32(rbutTest.Content);
rbutTest.Content = ((num + 1).ToString());
}
private void btnText_Click(object sender, RoutedEventArgs e)
{
int num = Convert.ToInt32(btnText.Content);
btnText.Content = ((num + 100).ToString());
}
// RepeatButton说明
// 表示从被按下到松开之前重复引发其单击事件的按钮。
// RepeatButton 控件包含用于指定单击重复之前的延迟以及两次单击之间的间隔的属性。
3. 自动断字换行 (TextWrapping )
Code
//Xaml写法
//TextWrapping = "Wrap"即可。
//注意:只有当Text内容长度超过TextBox的总长度时才会自动换行,上次听新人(比我还新)说怎么没效果,后来发现他的
//这个Grid.Row="0" Grid.Column="4" 的列宽是Auto属性。
<TextBox Margin="10" HorizontalAlignment="Left" Text="TextBox with a line of text that wraps." FontFamily="Arial" TextWrapping="Wrap" Grid.Row="0" Grid.Column="4" />
//Cs写法
TextBox txtWarp= new TextBox();
txtWarp.Text = "TextBox with a line of text that wraps.";
txtWarp.FontFamily = new FontFamily("Arial");
txtWarp.TextWrapping = TextWrapping.Wrap;
txtWarp.Width = 100.0;
LayoutRoot.Children.Add(txtWarp);
)//Xaml写法
//TextWrapping = "Wrap"即可。
//注意:只有当Text内容长度超过TextBox的总长度时才会自动换行,上次听新人(比我还新)说怎么没效果,后来发现他的
//这个Grid.Row="0" Grid.Column="4" 的列宽是Auto属性。
<TextBox Margin="10" HorizontalAlignment="Left" Text="TextBox with a line of text that wraps." FontFamily="Arial" TextWrapping="Wrap" Grid.Row="0" Grid.Column="4" />
//Cs写法
TextBox txtWarp= new TextBox();
txtWarp.Text = "TextBox with a line of text that wraps.";
txtWarp.FontFamily = new FontFamily("Arial");
txtWarp.TextWrapping = TextWrapping.Wrap;
txtWarp.Width = 100.0;
LayoutRoot.Children.Add(txtWarp);