2012-04-21 121 views
0

我有创建滚动的文字和我的主窗口的动画我这样称呼它的用户控件分离选取框:添加多个文本串到一个段落

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"主窗口,但我怎么能设置在后面的代码内容,我怎么可以设置多个MarqueeContents?

例如,即使我能够从后面的代码中设置MarqueeContent,并且我添加了多个项目,它无疑会像刚刚读取的文本一样依次添加它,因此我需要它如果有意义,我添加的项目至少有一个段落间距。

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

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

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

+1

但是你不想让这些项目独立地进行动画,只需要在行之间有段落间距的文本移动块? – Clemens 2012-04-21 07:59:04

回答

1

如果只是有关添加多行文本到一个移动块,你可以简单地添加换行符字里行间:

textBlock.Text = "A line of text.\n\nAnother line of text."; 

或者你也可以做同样的Inlines

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.")); 
+0

谢谢克莱门斯,工作! – 2012-04-21 20:55:48

相关问题