Is there a WPF way of following the end of a text in a TextBox with no NoWrap












3















I have a text box in xaml:



<TextBox Name="Text" HorizontalAlignment="Left" Height="75"   VerticalContentAlignment="Center" TextWrapping="NoWrap" Text="TextBox" Width="336"  BorderBrush="Black" FontSize="40" />


I add text to it with this method:



private string words = "Initial text contents of the TextBox.";

public async void textRotation()
{
for(int a =0; a < words.Length; a++)
{
Text.Text = words.Substring(0,a);
await Task.Delay(500);
}
}


Once the text goes of out of the wrap is there a way to focus the end so the old text disappears to the left and the new on the right, as opposed to just adding it to the right without seeing.










share|improve this question





























    3















    I have a text box in xaml:



    <TextBox Name="Text" HorizontalAlignment="Left" Height="75"   VerticalContentAlignment="Center" TextWrapping="NoWrap" Text="TextBox" Width="336"  BorderBrush="Black" FontSize="40" />


    I add text to it with this method:



    private string words = "Initial text contents of the TextBox.";

    public async void textRotation()
    {
    for(int a =0; a < words.Length; a++)
    {
    Text.Text = words.Substring(0,a);
    await Task.Delay(500);
    }
    }


    Once the text goes of out of the wrap is there a way to focus the end so the old text disappears to the left and the new on the right, as opposed to just adding it to the right without seeing.










    share|improve this question



























      3












      3








      3








      I have a text box in xaml:



      <TextBox Name="Text" HorizontalAlignment="Left" Height="75"   VerticalContentAlignment="Center" TextWrapping="NoWrap" Text="TextBox" Width="336"  BorderBrush="Black" FontSize="40" />


      I add text to it with this method:



      private string words = "Initial text contents of the TextBox.";

      public async void textRotation()
      {
      for(int a =0; a < words.Length; a++)
      {
      Text.Text = words.Substring(0,a);
      await Task.Delay(500);
      }
      }


      Once the text goes of out of the wrap is there a way to focus the end so the old text disappears to the left and the new on the right, as opposed to just adding it to the right without seeing.










      share|improve this question
















      I have a text box in xaml:



      <TextBox Name="Text" HorizontalAlignment="Left" Height="75"   VerticalContentAlignment="Center" TextWrapping="NoWrap" Text="TextBox" Width="336"  BorderBrush="Black" FontSize="40" />


      I add text to it with this method:



      private string words = "Initial text contents of the TextBox.";

      public async void textRotation()
      {
      for(int a =0; a < words.Length; a++)
      {
      Text.Text = words.Substring(0,a);
      await Task.Delay(500);
      }
      }


      Once the text goes of out of the wrap is there a way to focus the end so the old text disappears to the left and the new on the right, as opposed to just adding it to the right without seeing.







      c# wpf






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 1 at 1:44







      Ira W

















      asked Dec 31 '18 at 16:58









      Ira WIra W

      287




      287
























          2 Answers
          2






          active

          oldest

          votes


















          4














          A quick method is to measure the string (words) that needs scrolling with TextRenderer.MeasureText, divide the width measure in parts equals to the number of chars in the string and use ScrollToHorizontalOffset() to perform the scroll:



          public async void textRotation()
          {
          float TextPart = TextRenderer.MeasureText(words, new Font(Text.FontFamily.Source, (float)Text.FontSize)).Width / words.Length;
          for (int a = 0; a < words.Length; a++)
          {
          Text.Text = words.Substring(0, a);
          await Task.Delay(100);
          Text.ScrollToHorizontalOffset(TextPart * a);
          }
          }


          Using the FormattedText class to measure the string:



              public async void textRotation()
          {
          FormattedText TextFormat = new FormattedText(
          words, CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight,
          new Typeface(this.Text.FontFamily, this.Text.FontStyle, this.Text.FontWeight, this.Text.FontStretch),
          this.Text.FontSize, null, null, 1);

          float TextPart = (float)TextFormat.Width / words.Length;
          for (int a = 0; a < words.Length; a++)
          {
          Text.Text = words.Substring(0, a);
          await Task.Delay(200);
          Text.ScrollToHorizontalOffset(TextPart * a);
          }
          }


          enter image description here






          share|improve this answer


























          • Im getting an error "The name 'TextRenderer' does not exist in the current context" Im usure why, im using System.Windows which should cover it ?

            – Ira W
            Dec 31 '18 at 19:06











          • See the update, using FormattedText.

            – Jimi
            Dec 31 '18 at 19:28



















          1














          It should be fairly easy to achieve, try to add this code:



          public async void textRotation()
          {
          for(int a =0; a < words.Length; a++)
          {
          Text.Text = words.Substring(0,a);
          Text.ScrollToHorizontalOffset(Text.Text.Last());
          await Task.Delay(500);

          }
          }





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53989719%2fis-there-a-wpf-way-of-following-the-end-of-a-text-in-a-textbox-with-no-nowrap%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            4














            A quick method is to measure the string (words) that needs scrolling with TextRenderer.MeasureText, divide the width measure in parts equals to the number of chars in the string and use ScrollToHorizontalOffset() to perform the scroll:



            public async void textRotation()
            {
            float TextPart = TextRenderer.MeasureText(words, new Font(Text.FontFamily.Source, (float)Text.FontSize)).Width / words.Length;
            for (int a = 0; a < words.Length; a++)
            {
            Text.Text = words.Substring(0, a);
            await Task.Delay(100);
            Text.ScrollToHorizontalOffset(TextPart * a);
            }
            }


            Using the FormattedText class to measure the string:



                public async void textRotation()
            {
            FormattedText TextFormat = new FormattedText(
            words, CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight,
            new Typeface(this.Text.FontFamily, this.Text.FontStyle, this.Text.FontWeight, this.Text.FontStretch),
            this.Text.FontSize, null, null, 1);

            float TextPart = (float)TextFormat.Width / words.Length;
            for (int a = 0; a < words.Length; a++)
            {
            Text.Text = words.Substring(0, a);
            await Task.Delay(200);
            Text.ScrollToHorizontalOffset(TextPart * a);
            }
            }


            enter image description here






            share|improve this answer


























            • Im getting an error "The name 'TextRenderer' does not exist in the current context" Im usure why, im using System.Windows which should cover it ?

              – Ira W
              Dec 31 '18 at 19:06











            • See the update, using FormattedText.

              – Jimi
              Dec 31 '18 at 19:28
















            4














            A quick method is to measure the string (words) that needs scrolling with TextRenderer.MeasureText, divide the width measure in parts equals to the number of chars in the string and use ScrollToHorizontalOffset() to perform the scroll:



            public async void textRotation()
            {
            float TextPart = TextRenderer.MeasureText(words, new Font(Text.FontFamily.Source, (float)Text.FontSize)).Width / words.Length;
            for (int a = 0; a < words.Length; a++)
            {
            Text.Text = words.Substring(0, a);
            await Task.Delay(100);
            Text.ScrollToHorizontalOffset(TextPart * a);
            }
            }


            Using the FormattedText class to measure the string:



                public async void textRotation()
            {
            FormattedText TextFormat = new FormattedText(
            words, CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight,
            new Typeface(this.Text.FontFamily, this.Text.FontStyle, this.Text.FontWeight, this.Text.FontStretch),
            this.Text.FontSize, null, null, 1);

            float TextPart = (float)TextFormat.Width / words.Length;
            for (int a = 0; a < words.Length; a++)
            {
            Text.Text = words.Substring(0, a);
            await Task.Delay(200);
            Text.ScrollToHorizontalOffset(TextPart * a);
            }
            }


            enter image description here






            share|improve this answer


























            • Im getting an error "The name 'TextRenderer' does not exist in the current context" Im usure why, im using System.Windows which should cover it ?

              – Ira W
              Dec 31 '18 at 19:06











            • See the update, using FormattedText.

              – Jimi
              Dec 31 '18 at 19:28














            4












            4








            4







            A quick method is to measure the string (words) that needs scrolling with TextRenderer.MeasureText, divide the width measure in parts equals to the number of chars in the string and use ScrollToHorizontalOffset() to perform the scroll:



            public async void textRotation()
            {
            float TextPart = TextRenderer.MeasureText(words, new Font(Text.FontFamily.Source, (float)Text.FontSize)).Width / words.Length;
            for (int a = 0; a < words.Length; a++)
            {
            Text.Text = words.Substring(0, a);
            await Task.Delay(100);
            Text.ScrollToHorizontalOffset(TextPart * a);
            }
            }


            Using the FormattedText class to measure the string:



                public async void textRotation()
            {
            FormattedText TextFormat = new FormattedText(
            words, CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight,
            new Typeface(this.Text.FontFamily, this.Text.FontStyle, this.Text.FontWeight, this.Text.FontStretch),
            this.Text.FontSize, null, null, 1);

            float TextPart = (float)TextFormat.Width / words.Length;
            for (int a = 0; a < words.Length; a++)
            {
            Text.Text = words.Substring(0, a);
            await Task.Delay(200);
            Text.ScrollToHorizontalOffset(TextPart * a);
            }
            }


            enter image description here






            share|improve this answer















            A quick method is to measure the string (words) that needs scrolling with TextRenderer.MeasureText, divide the width measure in parts equals to the number of chars in the string and use ScrollToHorizontalOffset() to perform the scroll:



            public async void textRotation()
            {
            float TextPart = TextRenderer.MeasureText(words, new Font(Text.FontFamily.Source, (float)Text.FontSize)).Width / words.Length;
            for (int a = 0; a < words.Length; a++)
            {
            Text.Text = words.Substring(0, a);
            await Task.Delay(100);
            Text.ScrollToHorizontalOffset(TextPart * a);
            }
            }


            Using the FormattedText class to measure the string:



                public async void textRotation()
            {
            FormattedText TextFormat = new FormattedText(
            words, CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight,
            new Typeface(this.Text.FontFamily, this.Text.FontStyle, this.Text.FontWeight, this.Text.FontStretch),
            this.Text.FontSize, null, null, 1);

            float TextPart = (float)TextFormat.Width / words.Length;
            for (int a = 0; a < words.Length; a++)
            {
            Text.Text = words.Substring(0, a);
            await Task.Delay(200);
            Text.ScrollToHorizontalOffset(TextPart * a);
            }
            }


            enter image description here







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 31 '18 at 21:53

























            answered Dec 31 '18 at 18:13









            JimiJimi

            8,45241934




            8,45241934













            • Im getting an error "The name 'TextRenderer' does not exist in the current context" Im usure why, im using System.Windows which should cover it ?

              – Ira W
              Dec 31 '18 at 19:06











            • See the update, using FormattedText.

              – Jimi
              Dec 31 '18 at 19:28



















            • Im getting an error "The name 'TextRenderer' does not exist in the current context" Im usure why, im using System.Windows which should cover it ?

              – Ira W
              Dec 31 '18 at 19:06











            • See the update, using FormattedText.

              – Jimi
              Dec 31 '18 at 19:28

















            Im getting an error "The name 'TextRenderer' does not exist in the current context" Im usure why, im using System.Windows which should cover it ?

            – Ira W
            Dec 31 '18 at 19:06





            Im getting an error "The name 'TextRenderer' does not exist in the current context" Im usure why, im using System.Windows which should cover it ?

            – Ira W
            Dec 31 '18 at 19:06













            See the update, using FormattedText.

            – Jimi
            Dec 31 '18 at 19:28





            See the update, using FormattedText.

            – Jimi
            Dec 31 '18 at 19:28













            1














            It should be fairly easy to achieve, try to add this code:



            public async void textRotation()
            {
            for(int a =0; a < words.Length; a++)
            {
            Text.Text = words.Substring(0,a);
            Text.ScrollToHorizontalOffset(Text.Text.Last());
            await Task.Delay(500);

            }
            }





            share|improve this answer




























              1














              It should be fairly easy to achieve, try to add this code:



              public async void textRotation()
              {
              for(int a =0; a < words.Length; a++)
              {
              Text.Text = words.Substring(0,a);
              Text.ScrollToHorizontalOffset(Text.Text.Last());
              await Task.Delay(500);

              }
              }





              share|improve this answer


























                1












                1








                1







                It should be fairly easy to achieve, try to add this code:



                public async void textRotation()
                {
                for(int a =0; a < words.Length; a++)
                {
                Text.Text = words.Substring(0,a);
                Text.ScrollToHorizontalOffset(Text.Text.Last());
                await Task.Delay(500);

                }
                }





                share|improve this answer













                It should be fairly easy to achieve, try to add this code:



                public async void textRotation()
                {
                for(int a =0; a < words.Length; a++)
                {
                Text.Text = words.Substring(0,a);
                Text.ScrollToHorizontalOffset(Text.Text.Last());
                await Task.Delay(500);

                }
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 31 '18 at 18:43









                Dark TemplarDark Templar

                75259




                75259






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53989719%2fis-there-a-wpf-way-of-following-the-end-of-a-text-in-a-textbox-with-no-nowrap%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas