Click here to Skip to main content
15,911,139 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to show error Message to user, but error should display in blinking manner
I don't know how to do it in wpf.
so please help me.
thank you
sushil

What I have tried:

I tried TextDecoration property but it is not in wpf may be. i dont know.
Posted
Updated 22-Mar-16 23:35pm
Comments
Sinisa Hajnal 15-Feb-16 2:53am    
Don't do blinking messages. That is bad design and known as such for years. At least, not permanent blinking. Couple of blinks and then stop is OK.

You can do it with timer that shows and hides the control for quarter of the second or so and repeat that several times.
[no name] 16-Feb-16 20:28pm    
You will need to use the timer control, and set how many milliseconds you wish for ticks to update your label control by hiding, and showing your control again as per timer tick handler. All you need is here: https://msdn.microsoft.com/en-us/library/system.timers.timer(v=vs.110).aspx
Ammar Shaukat 30-Jan-18 2:28am    
@Sinisa Hajnal , your solution is good. We can make a function that will take few parameters like , total time in seconds and an Int that will decide how many times a label will blink in 1 second.

Have you considered using a animation to control the blinking message ? For an example I have simply added a button and a textblock to XAML. Then created a click event for the button.

C#
<Grid>
        <Button x:Name="button" Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Click="button_Click"/>
        <TextBlock x:Name="textBlock" HorizontalAlignment="Left" TextWrapping="Wrap" Text="Warning" VerticalAlignment="Top" Margin="0,26,0,0"/>

    </Grid>


And then add the following to my main windows.

C#
public partial class MainWindow : Window
    {
        DoubleAnimation da = new DoubleAnimation();
        public MainWindow()
        {
            InitializeComponent();
           
            da.From = 30;
            da.To = 35;
            da.AutoReverse = true;
            da.RepeatBehavior = new RepeatBehavior(3);
            da.Duration = new Duration(TimeSpan.FromSeconds(0.5));
            
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            textBlock.BeginAnimation(TextBlock.FontSizeProperty, da);
        }
    }


This
 
Share this answer
 
v3
Comments
Ammar Shaukat 21-Mar-18 5:20am    
Thanks
Declare This StoryBoard in Resources
HTML
<storyboard x:key="FlashMe"
                        RepeatBehavior="Forever">
                <objectanimationusingkeyframes storyboard.targetproperty="(UIElement.Visibility)">
                    <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>
                </objectanimationusingkeyframes>
            </storyboard>


& in Your ButtonClickEvent

write

textBox.BeginStoryboard(FindResource("FlashMe") as Storyboard);
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900