I am trying to make a custom control in WPF. I want it to simulate the behavior of a LED that can blink.
There are three states to the control: On, Off, and Blinking.
I know how to set On and Off through the code behind, but this WPF animation stuff is just driving me nuts!!!! I cannot get anything to animate whatsoever. The plan is to have a property called state. When the user sets the value to blinking, I want the control to alternate between green and grey. I’m assuming I need a dependency property here, but have no idea.
I had more xaml before but just erased it all. it doesn’t seem to do anything.
I’d love to do this in the most best practice way possible, but at this point, I’ll take anything. I’m half way to writing a thread that changes the color manually at this point.
<UserControl x:Class="WpfAnimation.LED"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Grid>
<Ellipse x:Name="MyLight" Height="Auto" Width="Auto"/>
</Grid>
</UserControl>
You can do this with an animation that auto-reverses and repeats (this is for Silverlight):
and then start the animation when the control loads or when a property is set – you don’t need a dependency property unless you
or on startup:
Here is another way to do it in WPF – using the VisualStateManager – that will also work in Silverlight:
and then have the IsBlinking property switch the visual state: