none
Make text flashing

    Question

  • I have the code.

    <TextBlock Grid.Row="1" Text="***OLD DATA***" TextAlignment="Center" FontSize="12" FontWeight="Bold" Foreground="Red" ></TextBlock>
    <TextBlock Grid.Row="2" Text="NO CHANGES ARE ALLOWED" TextAlignment="Center" FontSize="12" FontWeight="Bold" Foreground="Red" ></TextBlock>

    Now I want to make them flashing. Please see the demo

    How?


    • Edited by HZ.USA Friday, February 03, 2017 8:35 PM add url
    Friday, February 03, 2017 8:21 PM

Answers

  • Hi HZ.USA,

    >> But I want it blinks forever, how?

    Please set RepeatBehavior property for the StoryBoard as "Forever", which will let the textblock blinks forever.

    <Storyboard x:Name="Storyboard1" RepeatBehavior="Forever">

    >> Also I want two textblock flashing using one StoryBoard.

    Please bind the "***OLD DATA***" TextBlock's Visibility property to "NO CHANGES ARE ALLOWED" TextBlock control. Please refer to following sample code.

     <TextBlock x:Name="textBlock" Grid.Row="1" Text="***OLD DATA***" TextAlignment="Center" FontSize="12" FontWeight="Bold" Foreground="Red"/>
     <TextBlock x:Name="textBlock2" Grid.Row="2" Text="NO CHANGES ARE ALLOWED" Visibility="{Binding Visibility, ElementName=textBlock}" TextAlignment="Center" FontSize="12" FontWeight="Bold" Foreground="Red" ></TextBlock>
    Best Regards,
    Weiwei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by HZ.USA Thursday, February 09, 2017 1:25 PM
    Thursday, February 09, 2017 2:23 AM
    Moderator

All replies

  • Hi HZ.USA,

    We could use storyboard through Visual Studio Blend to implement animation on an XAML element. Following MSDN document introduce how to create Storyboard in Visual Studio Blend. Hope it can help you.

    https://msdn.microsoft.com/en-us/library/cc295300(v=expression.40).aspx

    And following code is the generated code when using Blend implement text flashing for one of your TextBlock control.

     <UserControl.Resources>
            <Storyboard x:Name="Storyboard1">
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock">
                    <DiscreteObjectKeyFrame KeyTime="0:0:0.5">
                        <DiscreteObjectKeyFrame.Value>
                            <Visibility>Collapsed</Visibility>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                    <DiscreteObjectKeyFrame KeyTime="0:0:1">
                        <DiscreteObjectKeyFrame.Value>
                            <Visibility>Visible</Visibility>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                    <DiscreteObjectKeyFrame KeyTime="0:0:1.5">
                        <DiscreteObjectKeyFrame.Value>
                            <Visibility>Collapsed</Visibility>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                    <DiscreteObjectKeyFrame KeyTime="0:0:2">
                        <DiscreteObjectKeyFrame.Value>
                            <Visibility>Visible</Visibility>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                    <DiscreteObjectKeyFrame KeyTime="0:0:2.5">
                        <DiscreteObjectKeyFrame.Value>
                            <Visibility>Collapsed</Visibility>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                    <DiscreteObjectKeyFrame KeyTime="0:0:3">
                        <DiscreteObjectKeyFrame.Value>
                            <Visibility>Visible</Visibility>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                    <DiscreteObjectKeyFrame KeyTime="0:0:3.5">
                        <DiscreteObjectKeyFrame.Value>
                            <Visibility>Collapsed</Visibility>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                    <DiscreteObjectKeyFrame KeyTime="0:0:4">
                        <DiscreteObjectKeyFrame.Value>
                            <Visibility>Collapsed</Visibility>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                    <DiscreteObjectKeyFrame KeyTime="0:0:4.5">
                        <DiscreteObjectKeyFrame.Value>
                            <Visibility>Visible</Visibility>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
        </UserControl.Resources>

    After create storyboard, please remember to start this storyboard on your code behind.

            public MainPage()
            {
                InitializeComponent();
                Storyboard1.Begin();
            }

    Best Regards,
    Weiwei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 06, 2017 2:09 AM
    Moderator
  • It is not working.
    Monday, February 06, 2017 1:46 PM
  • Hi HZ.USA,

    Above sample code, I only add a storyboard for "***OLD DATA***" TextBlock. So you need to add another storyboard for "NO CHANGES ARE ALLOWED" TextBlock control.

    I have upload the entire sample project to OneDrive, you could download it and check whether there has any difference between your code. My sample code also just add a storyboard for "***OLD DATA***" TextBlock. So you just need to verify whether the "***OLD DATA***" TextBlock works or not.

    https://1drv.ms/u/s!AkHKK8SV6besg2iIinYOTSICQVxf

    If possible, you also could share your code here, which will help us find out what happened in your code.

    Best Regards,
    Weiwei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 07, 2017 1:02 AM
    Moderator
  • I use pure Visual Studio 2010 professional edition only. (No Blend available for this edition) Would you please provide one in VS 2010?
    • Edited by HZ.USA Tuesday, February 07, 2017 2:00 PM edit
    Tuesday, February 07, 2017 1:24 PM
  • Hi HZ.USA,

    I don't have VS2010 Professional edition, but I have VS2010 Ultimate edition. So following demo is working fine in VS2010 Ultimate edition.

    https://1drv.ms/u/s!AkHKK8SV6besg2mGCIP6BPxx-Fum

    You could copy the XAML code into your Silverlight page and please don't forget to begin the storyboard in code-behind.

     public MainPage()
     {
          InitializeComponent();
          Storyboard1.Begin();
     }

    If it still doesn't work in your code, please share your sample code here. I will check what happened in your code.

    Best Regards,
    Weiwei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 08, 2017 2:56 AM
    Moderator
  • It seems works now. It blinks for several seconds. But I want it blinks forever, how? Also I want two textblock flashing using one StoryBoard.
    • Edited by HZ.USA Wednesday, February 08, 2017 7:01 PM add
    Wednesday, February 08, 2017 6:58 PM
  • Hi HZ.USA,

    >> But I want it blinks forever, how?

    Please set RepeatBehavior property for the StoryBoard as "Forever", which will let the textblock blinks forever.

    <Storyboard x:Name="Storyboard1" RepeatBehavior="Forever">

    >> Also I want two textblock flashing using one StoryBoard.

    Please bind the "***OLD DATA***" TextBlock's Visibility property to "NO CHANGES ARE ALLOWED" TextBlock control. Please refer to following sample code.

     <TextBlock x:Name="textBlock" Grid.Row="1" Text="***OLD DATA***" TextAlignment="Center" FontSize="12" FontWeight="Bold" Foreground="Red"/>
     <TextBlock x:Name="textBlock2" Grid.Row="2" Text="NO CHANGES ARE ALLOWED" Visibility="{Binding Visibility, ElementName=textBlock}" TextAlignment="Center" FontSize="12" FontWeight="Bold" Foreground="Red" ></TextBlock>
    Best Regards,
    Weiwei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by HZ.USA Thursday, February 09, 2017 1:25 PM
    Thursday, February 09, 2017 2:23 AM
    Moderator