gpt4 book ai didi

c# - 以编程方式设置文本 block 边距

转载 作者:太空狗 更新时间:2023-10-29 19:52:02 27 4
gpt4 key购买 nike

我想知道如何以编程方式设置文本 block 的边距?我有一个字符串列表,我想将其分配给每个文本 block 并为每个文本 block 设置动画,每个文本 block 之间都有一个间距。刚才,所有的文本 block 都在同一行,所以我看不懂文本在说什么。

foreach (var i in item.Items)
{
TextBlock tb = new TextBlock();
tb.Height = 50;
tb.Width = 900;
tb.Text = i.Title + "\n";

SlideDown(tb);
canvas.Children.Add(tb);
}

public void SlideDown(FrameworkElement uc)
{
ThicknessAnimation tAnimation = new ThicknessAnimation();
tAnimation.Duration = new Duration(TimeSpan.FromSeconds(5.0));
tAnimation.From = new Thickness(0,0,0,0);
tAnimation.To = new Thickness(0, 500, 0, 500);
Storyboard.SetTarget(tAnimation, uc);
Storyboard.SetTargetProperty(tAnimation, new PropertyPath(FrameworkElement.MarginProperty));
Storyboard storyboard = new Storyboard();
storyboard.Children.Add(tAnimation);
storyboard.Begin(uc);
}

最佳答案

您可以像这样设置 Margin 属性:

  double left = 1, top = 2, right = 3, bottom = 4;
textBlock.Margin = new Thickness(left, top, right, bottom);

或者您可以指定适用于以上所有内容的单个值:

  double all = 5;
textBlock.Margin = new Thickness(all);

关于c# - 以编程方式设置文本 block 边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9707753/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com