Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 389889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:54:39+00:00 2026-05-12T15:54:39+00:00

I am trying to make a custom control in WPF. I want it to

  • 0

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T15:54:40+00:00Added an answer on May 12, 2026 at 3:54 pm

    You can do this with an animation that auto-reverses and repeats (this is for Silverlight):

    <UserControl
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Class="Blinker.MainPage"
        Width="640" Height="480" Loaded="UserControl_Loaded">
        <UserControl.Resources>
            <Storyboard x:Name="Blink" AutoReverse="True" RepeatBehavior="Forever">
                <ColorAnimationUsingKeyFrames BeginTime="00:00:00"
                  Storyboard.TargetName="ellipse"
                  Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
                     <EasingColorKeyFrame KeyTime="00:00:01" Value="Gray"/>
                </ColorAnimationUsingKeyFrames>
             </Storyboard>
        </UserControl.Resources>
        <Grid x:Name="LayoutRoot" Background="White">
             <Ellipse x:Name="ellipse" Fill="Green" Stroke="Black"/>
        </Grid>
    </UserControl>
    

    and then start the animation when the control loads or when a property is set – you don’t need a dependency property unless you

    private bool blinking;
    public bool IsBlinking
    {
        get
        {
           return blinking;
        }
        set
        {
            if (value)
            {
                 this.Blink.Begin();
            }
            else
            {
                 this.Blink.Stop();
            }
    
            this.blinking = value;
        }
    }
    

    or on startup:

    private void UserControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
    {
        this.Blink.Begin();
    }
    

    Here is another way to do it in WPF – using the VisualStateManager – that will also work in Silverlight:

    <UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="BlinkerApp.Blinker"
    x:Name="UserControl"
    d:DesignWidth="100" d:DesignHeight="100">
    <Grid x:Name="LayoutRoot">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="BlinkStates">
                <VisualState x:Name="Blinking">
                    <Storyboard AutoReverse="True" RepeatBehavior="Forever">
                        <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
                            <SplineColorKeyFrame KeyTime="00:00:01" Value="Gray"/>
                        </ColorAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Stopped"/>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Ellipse x:Name="ellipse" Fill="Green" Stroke="Black"/>
    </Grid>
    

    and then have the IsBlinking property switch the visual state:

    namespace BlinkerApp
    {
        using System.Windows;
        using System.Windows.Controls;
    
    /// <summary>
    /// Interaction logic for Blinker.xaml
    /// </summary>
    public partial class Blinker : UserControl
    {
        private bool blinking;
    
        public Blinker()
        {
            this.InitializeComponent();
        }
    
        public bool IsBlinking
        {    
            get    
            {       
                return blinking;    
            }    
    
            set    
            {        
                if (value)        
                {
                    VisualStateManager.GoToState(this, "Blinking", true);
                }        
                else        
                {
                    VisualStateManager.GoToState(this, "Stopped", true);
                }        
    
                this.blinking = value;    
            }
        }       
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a custom user control in WPF. I want to
I'm trying to make a custom swing control that is a meter. Swing Meter
I'm trying to make a custom WPF control where a TranslateTransform is applied based
I'm trying to create a custom control that can be shared by both Silverlight
So I'm trying to make a custom user control for a Windows Phone 7
I am trying to make Custom RelativeLayout which can scale and scroll. Right now
Trying to make a custom :confirm message for a rails form that returns data
I'm trying to make a custom converter that inherits from DependencyObject , but it
I'm trying to make a custom UITableViewCell as I need to have specific control
I'm trying to make a custom ContentControl that takes on the shape of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.