Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Text Ticker

Text Ticker

Scheduled Pinned Locked Moved WPF
csharpwpfhelptutorial
25 Posts 2 Posters 8 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KBou
    wrote on last edited by
    #1

    Hi, I'm using C# in a WPF Project and I need a TextBlock of Label that scrolls text from RightToLeft. I can't find a decent example or explaining on the internet. I have found an example that uses SubString but this doesn't give a smooth animation. I think WPF can do better. I need this in C# code not XAML. Hope some one can help me. Thanks. Kevin

    L 1 Reply Last reply
    0
    • K KBou

      Hi, I'm using C# in a WPF Project and I need a TextBlock of Label that scrolls text from RightToLeft. I can't find a decent example or explaining on the internet. I have found an example that uses SubString but this doesn't give a smooth animation. I think WPF can do better. I need this in C# code not XAML. Hope some one can help me. Thanks. Kevin

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I used Google and found this near the top of the search: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=871414&SiteID=1[^] Remember, anything done in XAML can be done in code. I would use a TranslateTransform animation. This gives to a lot of control over your text scrolling.

      Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

      Just a grain of sand on the worlds beaches.

      K 1 Reply Last reply
      0
      • L Lost User

        I used Google and found this near the top of the search: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=871414&SiteID=1[^] Remember, anything done in XAML can be done in code. I would use a TranslateTransform animation. This gives to a lot of control over your text scrolling.

        Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

        Just a grain of sand on the worlds beaches.

        K Offline
        K Offline
        KBou
        wrote on last edited by
        #3

        Remember, anything done in XAML can be done in code. I'll have to disagree with you on that one. Example try to Underline a Label. In Xaml you can do, < label > < underline > Some Text < \underline > < \label > Try to do that in code. I coudn't find it. I still didn't got it to work by the way. I must say I am only programming for half a year. I don't know how to do some things in the example in C# code.

        modified on Tuesday, April 29, 2008 9:46 AM

        L 1 Reply Last reply
        0
        • K KBou

          Remember, anything done in XAML can be done in code. I'll have to disagree with you on that one. Example try to Underline a Label. In Xaml you can do, < label > < underline > Some Text < \underline > < \label > Try to do that in code. I coudn't find it. I still didn't got it to work by the way. I must say I am only programming for half a year. I don't know how to do some things in the example in C# code.

          modified on Tuesday, April 29, 2008 9:46 AM

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          KBou wrote:

          I'll have to disagree with you on that one.

          Everything done in XAML can be done in code. All XAML gets compiled into code. Notice in the below example, the code just creates the same classes that the XAML does.

          <Window x:Class="Window1"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="Window1" Height="300" Width="300">
          <StackPanel x:Name="LayoutRoot">
          <Label>
          <Underline>Some Text</Underline>
          </Label>
          </StackPanel>
          </Window>

          Class Window1

          Private Sub Window1\_Loaded(ByVal sender As Object, \_
              ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
          
              Dim lbl As New Label
              Dim und As New Underline
              und.Inlines.Add("Hi from Code!")
              lbl.Content = und
              Me.LayoutRoot.Children.Add(lbl)
          
          End Sub
          

          End Class

          Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

          Just a grain of sand on the worlds beaches.

          K 1 Reply Last reply
          0
          • L Lost User

            KBou wrote:

            I'll have to disagree with you on that one.

            Everything done in XAML can be done in code. All XAML gets compiled into code. Notice in the below example, the code just creates the same classes that the XAML does.

            <Window x:Class="Window1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="Window1" Height="300" Width="300">
            <StackPanel x:Name="LayoutRoot">
            <Label>
            <Underline>Some Text</Underline>
            </Label>
            </StackPanel>
            </Window>

            Class Window1

            Private Sub Window1\_Loaded(ByVal sender As Object, \_
                ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
            
                Dim lbl As New Label
                Dim und As New Underline
                und.Inlines.Add("Hi from Code!")
                lbl.Content = und
                Me.LayoutRoot.Children.Add(lbl)
            
            End Sub
            

            End Class

            Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

            Just a grain of sand on the worlds beaches.

            K Offline
            K Offline
            KBou
            wrote on last edited by
            #5

            I'll take it back. Everything done in XAML can be done in code. But I would still like some help with an example in code because I can't get it to work propperly. Thanks for the Underline anyway :-D

            L 1 Reply Last reply
            0
            • K KBou

              I'll take it back. Everything done in XAML can be done in code. But I would still like some help with an example in code because I can't get it to work propperly. Thanks for the Underline anyway :-D

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              What exactly does not work? Here is a link to a super book on writing WPF Code. This is the link to the Source Code download that has lots of animiation code. http://www.microsoft.com/mspress/companion/0-7356-1957-3/[^] From what you wrote before, you want to scroll text. One way to accomplish this, is to us an animation and a TranslateTransform to change the position of the text. If you are on a canvas, you can animate the x & y points. You down load Express Blend 2.5 Preview for free. You can write and study doing this in a few minutes in Blend.

              Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

              Just a grain of sand on the worlds beaches.

              K 1 Reply Last reply
              0
              • L Lost User

                What exactly does not work? Here is a link to a super book on writing WPF Code. This is the link to the Source Code download that has lots of animiation code. http://www.microsoft.com/mspress/companion/0-7356-1957-3/[^] From what you wrote before, you want to scroll text. One way to accomplish this, is to us an animation and a TranslateTransform to change the position of the text. If you are on a canvas, you can animate the x & y points. You down load Express Blend 2.5 Preview for free. You can write and study doing this in a few minutes in Blend.

                Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

                Just a grain of sand on the worlds beaches.

                K Offline
                K Offline
                KBou
                wrote on last edited by
                #7

                Well I kinda got it to scroll the way I want. But... Here's the situation. I've got an UserControl that can contains a TextBlock. The text in the TextBlock should scroll from left to right, But the text shoudn't be visible when it's outside of the UserControl. This is what I have got so far.

                TextBlock tb = (TextBlock)this.Content;
                tb.FlowDirection = FlowDirection.LeftToRight;

                DoubleAnimation Animation = new DoubleAnimation();
                Animation.From = this.Width;
                Animation.To = -tb.DesiredSize.Width;
                Animation.Duration = new Duration(TimeSpan.FromSeconds(10));

                TranslateTransform tt = new TranslateTransform();
                tt.BeginAnimation(TranslateTransform.XProperty, Animation);
                tb.RenderTransform = tt;

                Any ideas how I can get the visibility part? And how do I use a storyboard in this for Repeating?

                L 1 Reply Last reply
                0
                • K KBou

                  Well I kinda got it to scroll the way I want. But... Here's the situation. I've got an UserControl that can contains a TextBlock. The text in the TextBlock should scroll from left to right, But the text shoudn't be visible when it's outside of the UserControl. This is what I have got so far.

                  TextBlock tb = (TextBlock)this.Content;
                  tb.FlowDirection = FlowDirection.LeftToRight;

                  DoubleAnimation Animation = new DoubleAnimation();
                  Animation.From = this.Width;
                  Animation.To = -tb.DesiredSize.Width;
                  Animation.Duration = new Duration(TimeSpan.FromSeconds(10));

                  TranslateTransform tt = new TranslateTransform();
                  tt.BeginAnimation(TranslateTransform.XProperty, Animation);
                  tb.RenderTransform = tt;

                  Any ideas how I can get the visibility part? And how do I use a storyboard in this for Repeating?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  KBou wrote:

                  Any ideas how I can get the visibility part?

                  Read up on the "ClipToBounds" property and set this on your UserControl. I'll assume that you have set a specific height and width on your UserControl. You should add a method to your UserControl so that the parent container can all the UserControl to start and/or stop the animation. A property for the TextBlock.Text is also in order unless the text is always the same.

                  KBou wrote:

                  And how do I use a storyboard in this for Repeating?

                  What are you trying to do? Have the animation keep repeating? Have the animation repeat on command? If so, is this command executed in code or XAML? You used the word storyboard, why? From the beginning you wanted a code only solution, what was the reason for a code only solution instead of using a XAML storyboard?

                  Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

                  Just a grain of sand on the worlds beaches.

                  K 1 Reply Last reply
                  0
                  • L Lost User

                    KBou wrote:

                    Any ideas how I can get the visibility part?

                    Read up on the "ClipToBounds" property and set this on your UserControl. I'll assume that you have set a specific height and width on your UserControl. You should add a method to your UserControl so that the parent container can all the UserControl to start and/or stop the animation. A property for the TextBlock.Text is also in order unless the text is always the same.

                    KBou wrote:

                    And how do I use a storyboard in this for Repeating?

                    What are you trying to do? Have the animation keep repeating? Have the animation repeat on command? If so, is this command executed in code or XAML? You used the word storyboard, why? From the beginning you wanted a code only solution, what was the reason for a code only solution instead of using a XAML storyboard?

                    Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

                    Just a grain of sand on the worlds beaches.

                    K Offline
                    K Offline
                    KBou
                    wrote on last edited by
                    #9

                    Thanks for the ClipToBounds. This works fine. I have a Canvas on wich the user can drag usercontrols wich can contain a textblock. From a contextmenu they can start the scrolling. The text must keep on scrolling until it is stopped by the user. The text in the textblock is continu changing, much like a news ticker. And i want all of this in code because the user is must be able to change things like speed, direction and he also had the ability to change the size of the usercontrol. I have methodes for setting the text and a methode that starts te animation, but now the animation only runs once. So what is the best way to keep the animation running until the users stops it? Thanks. Kevin

                    L 1 Reply Last reply
                    0
                    • K KBou

                      Thanks for the ClipToBounds. This works fine. I have a Canvas on wich the user can drag usercontrols wich can contain a textblock. From a contextmenu they can start the scrolling. The text must keep on scrolling until it is stopped by the user. The text in the textblock is continu changing, much like a news ticker. And i want all of this in code because the user is must be able to change things like speed, direction and he also had the ability to change the size of the usercontrol. I have methodes for setting the text and a methode that starts te animation, but now the animation only runs once. So what is the best way to keep the animation running until the users stops it? Thanks. Kevin

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      KBou wrote:

                      So what is the best way to keep the animation running until the users stops it?

                      Check out the "RepeatBehavior" property.

                      Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

                      Just a grain of sand on the worlds beaches.

                      K 1 Reply Last reply
                      0
                      • L Lost User

                        KBou wrote:

                        So what is the best way to keep the animation running until the users stops it?

                        Check out the "RepeatBehavior" property.

                        Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

                        Just a grain of sand on the worlds beaches.

                        K Offline
                        K Offline
                        KBou
                        wrote on last edited by
                        #11

                        Well I thaugt I had created what I wanted. But I saw some flaws. First of all you won't get a continuasly stream of text and second it won't show all the text that is my TextBlock wich is in a UserControl only what you can see from the beginning. So back to square one it is. I still need help with this. This must be posible. Kevin

                        L 1 Reply Last reply
                        0
                        • K KBou

                          Well I thaugt I had created what I wanted. But I saw some flaws. First of all you won't get a continuasly stream of text and second it won't show all the text that is my TextBlock wich is in a UserControl only what you can see from the beginning. So back to square one it is. I still need help with this. This must be posible. Kevin

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #12

                          Kevin, Now I'm more confused over the desired result. Can you mock this up with a few images so that we can "see" the desired results.

                          Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

                          Just a grain of sand on the worlds beaches.

                          K 1 Reply Last reply
                          0
                          • L Lost User

                            Kevin, Now I'm more confused over the desired result. Can you mock this up with a few images so that we can "see" the desired results.

                            Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

                            Just a grain of sand on the worlds beaches.

                            K Offline
                            K Offline
                            KBou
                            wrote on last edited by
                            #13

                            This is the idea: First Second It is only one string of text wich continues to scroll over the screen.

                            L 1 Reply Last reply
                            0
                            • K KBou

                              This is the idea: First Second It is only one string of text wich continues to scroll over the screen.

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #14

                              Have a look at this. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=871414&SiteID=1[^]

                              Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

                              Just a grain of sand on the worlds beaches.

                              K 1 Reply Last reply
                              0
                              • L Lost User

                                Have a look at this. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=871414&SiteID=1[^]

                                Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

                                Just a grain of sand on the worlds beaches.

                                K Offline
                                K Offline
                                KBou
                                wrote on last edited by
                                #15

                                I had a look at it and it only solves one of my problems. It only solves the problem of text that is bigger than the usercontrol/canvas. You still have to wait for the End of the text to reach the left of the screen before it will start over.

                                L 1 Reply Last reply
                                0
                                • K KBou

                                  I had a look at it and it only solves one of my problems. It only solves the problem of text that is bigger than the usercontrol/canvas. You still have to wait for the End of the text to reach the left of the screen before it will start over.

                                  L Offline
                                  L Offline
                                  Lost User
                                  wrote on last edited by
                                  #16

                                  Did you read the other post that was linked to in the article. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2475074&SiteID=1&mode=1[^]

                                  Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

                                  Just a grain of sand on the worlds beaches.

                                  K 1 Reply Last reply
                                  0
                                  • L Lost User

                                    Did you read the other post that was linked to in the article. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2475074&SiteID=1&mode=1[^]

                                    Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

                                    Just a grain of sand on the worlds beaches.

                                    K Offline
                                    K Offline
                                    KBou
                                    wrote on last edited by
                                    #17

                                    I've look at that i tried the "Answer" given on that page but I don't know what to do with the "SignConverter" part. The description says "The sign converter just takes a number and returns its negative value." So when I didn't knew what it exactly did I put it in commentary and ran the project and saw it wasn't doing what I want. But is that the part that ensures the text to start when is has not ended? Kevin By the way. Sorry for my crappy English.

                                    L 1 Reply Last reply
                                    0
                                    • K KBou

                                      I've look at that i tried the "Answer" given on that page but I don't know what to do with the "SignConverter" part. The description says "The sign converter just takes a number and returns its negative value." So when I didn't knew what it exactly did I put it in commentary and ran the project and saw it wasn't doing what I want. But is that the part that ensures the text to start when is has not ended? Kevin By the way. Sorry for my crappy English.

                                      L Offline
                                      L Offline
                                      Lost User
                                      wrote on last edited by
                                      #18

                                      Kevin, Your English is just fine, no worries. I'm SUPER busy for the next 2 weeks, almost every moment of the day is taken up with preparation for Code Camp and article writing. I might be easier to just write this. You need to create a class that exposes a circular buffer that you can read from, then using a System.Times.Timer in your UserControl display the text from the buffer. Write me in 2 weeks if you have not got this done and I'll write one and place it on my blog.

                                      Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

                                      Just a grain of sand on the worlds beaches.

                                      K 2 Replies Last reply
                                      0
                                      • L Lost User

                                        Kevin, Your English is just fine, no worries. I'm SUPER busy for the next 2 weeks, almost every moment of the day is taken up with preparation for Code Camp and article writing. I might be easier to just write this. You need to create a class that exposes a circular buffer that you can read from, then using a System.Times.Timer in your UserControl display the text from the buffer. Write me in 2 weeks if you have not got this done and I'll write one and place it on my blog.

                                        Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

                                        Just a grain of sand on the worlds beaches.

                                        K Offline
                                        K Offline
                                        KBou
                                        wrote on last edited by
                                        #19

                                        Well thanks for the idea i've never used something like a circular buffer before but i'll see if i can create one. Thanks for your help and good luck with Code Camp. I'll let you know in two week if I made any progress. Greets, Kevin

                                        1 Reply Last reply
                                        0
                                        • L Lost User

                                          Kevin, Your English is just fine, no worries. I'm SUPER busy for the next 2 weeks, almost every moment of the day is taken up with preparation for Code Camp and article writing. I might be easier to just write this. You need to create a class that exposes a circular buffer that you can read from, then using a System.Times.Timer in your UserControl display the text from the buffer. Write me in 2 weeks if you have not got this done and I'll write one and place it on my blog.

                                          Cheers, Karl » CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP Profile

                                          Just a grain of sand on the worlds beaches.

                                          K Offline
                                          K Offline
                                          KBou
                                          wrote on last edited by
                                          #20

                                          Well Karl, I got nowhere with a circular buffer so I put it aside and went on with some other things. But it often crossed my mind and from what I got to understand of the idea you would still remove a character at the beginning an add one at the end. Would this give you a "smooth animation"? Thanks, Kevin

                                          L 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups