WPF后台代码实现TextBlock滚动条
2021-02-08 05:17
标签:操作 img bar idt 代码实现 文本 ext mic 滚动条 方法一: 常规的WPF操作: 后台代码: 方法二: 后台直接写: WPF后台代码实现TextBlock滚动条 标签:操作 img bar idt 代码实现 文本 ext mic 滚动条 原文地址:https://www.cnblogs.com/carmen-019/p/11363634.html
_txtb.Text = "1\r\n7\r\n6\r\n5dsaadsfjhduhtndsadjdhsajhscadsadsadas哈哈哈你\r\n4\r\n3\r\n2\r\n1\r\n0\r\n1\r\n2";
public MainWindow()
{
InitializeComponent();
var outer = new ScrollViewer();
outer.Background = Brushes.Gray;
outer.Width = 300;
outer.Height = 100;
var inner = new TextBlock();
inner.Background = Brushes.Orange;
inner.Foreground = Brushes.White;
inner.Width = 200;
outer.Content = inner;
outer.MaxHeight = 80;
inner.Text = "1\r\n7\r\n6\r\n5dsaadsfjhduhtndsadjdhsajhscadsadsadas哈哈哈你\r\n4\r\n3\r\n2\r\n1\r\n0\r\n1\r\n2";
// 此行用于文本内容根据设定宽度,当一行过长时自动换行
// inner.TextWrapping = TextWrapping.Wrap;
outer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
outer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
// 此句慎用呀,此处主要为了在界面上显示出结果
this.Content = outer;
}
文章标题:WPF后台代码实现TextBlock滚动条
文章链接:http://soscw.com/index.php/essay/52502.html