将多个文本字符串添加到由段落分隔的选框



我有一个用户控件,它可以创建滚动文本的动画,在我的主窗口中,我这样称呼它:

xmlns:mar="clr-namespace:WpfApplication4.AppPages"
<mar:Feed Background="DarkGray" FontSize="12" MarqueeTimeInSeconds="8" 
          Foreground="Gray" Margin="7,383,711,6" MarqueeContent="Live Feed" 
          MarqueeType="TopToBottom"></mar:Feed>

用户控件的代码如下所示:

    MarqueeType _marqueeType;
    public MarqueeType MarqueeType
    {
        get { return _marqueeType; }
        set { _marqueeType = value; }
    }       
    public String MarqueeContent
    {
        set { tbmarquee.Text = value; }
    }
    private double _marqueeTimeInSeconds;
    public double MarqueeTimeInSeconds
    {
        get { return _marqueeTimeInSeconds; }
        set { _marqueeTimeInSeconds = value; }
    }
    public Feed()
    {
        InitializeComponent();
        canMain.Height = this.Height;
        canMain.Width = this.Width;
        this.Loaded += new RoutedEventHandler(Feed_Loaded);
    }
    void Feed_Loaded(object sender, RoutedEventArgs e)
    {
        StartMarqueeing(_marqueeType);
    }
    public void StartMarqueeing(MarqueeType marqueeType)
    {
            TopToBottomMarquee();
    }
    private void TopToBottomMarquee()
    {
        double width = canMain.ActualWidth - tbmarquee.ActualWidth;
        tbmarquee.Margin = new Thickness(width / 2, 0, 0, 0);
        DoubleAnimation doubleAnimation = new DoubleAnimation();
        doubleAnimation.From = -tbmarquee.ActualHeight;
        doubleAnimation.To = canMain.ActualHeight;
        doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
        doubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(_marqueeTimeInSeconds));
        tbmarquee.BeginAnimation(Canvas.TopProperty, doubleAnimation);
    }
public enum MarqueeType
{
    TopToBottom
}

在主窗口中,我像这样设置了 xaml MarqueeContent="Live Feed",但我如何在代码隐藏中设置内容以及如何设置多个 MarqueeContent?

例如,即使我能够从代码隐藏中设置 MarqueeContent 并向其中添加多个项目,它无疑也会像您刚才阅读的文本一样一个接一个地添加它,我需要它,所以我添加的每个项目至少有一个段落间距如果有意义。

为了给出一个视觉概念,你可以在这里看到它(自上而下):

http://www.codeproject.com/Articles/48267/Making-a-Simple-Marquee-Text-Control-Drip-Animatio

我需要它,以便我可以将多个字符串加载到其中。并且添加的每个文本字符串都由一个段落分隔。

如果只是将多行文本添加到一个移动块,您可以简单地在行之间添加换行符:

textBlock.Text = "A line of text.nnAnother line of text.";

或者你可以对内联做同样的事情:

textBlock.Inlines.Add(new Run("A line of text."));
textBlock.Inlines.Add(new LineBreak());
textBlock.Inlines.Add(new LineBreak());
textBlock.Inlines.Add(new Run("Another line of text."));

最新更新