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 683575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:43:21+00:00 2026-05-14T01:43:21+00:00

I am not looking to create new events. I need to create a canvas

  • 0

I am not looking to create new events. I need to create a canvas control that optionally fades in or out depending on whether or not the mouse is over it. The code below probably explains what I want to do better than I can.

        private Storyboard fadeInStoryboard;
    private Storyboard fadeOutStoryboard;
    public FadingOptionPanel()
    {
        InitializeComponent();
    }
    public static readonly DependencyProperty FadeEnabledProperty =
    DependencyProperty.Register("IsFadeEnabled", typeof(bool), typeof(FadingOptionPanel), new FrameworkPropertyMetadata(true,
                   OnFadeEnabledPropertyChanged,
                   OnCoerceFadeEnabledProperty));
    public bool IsFadeEnabled
    {
        get
        {
            return (bool)GetValue(FadeEnabledProperty);
        }
        set
        {
            SetValue(FadeEnabledProperty, value);
        }
    }
    private static void OnFadeEnabledPropertyChanged(DependencyObject source,
    DependencyPropertyChangedEventArgs e)
    {

    }
    private static object OnCoerceFadeEnabledProperty(DependencyObject sender, object data)
    {
        if (data.GetType() != typeof(bool))
        {
            data = true;
        }
        return data;
    }

    private void FadingOptionPanel_MouseEnter(object sender, MouseEventArgs e)
    {
        if (IsFadeEnabled)
        {
            fadeInStoryboard.Begin(this);
        }
    }
    private void FadingOptionPanel_MouseLeave(object sender, MouseEventArgs e)
    {
        if (IsFadeEnabled)
        {
            fadeOutStoryboard.Begin(this);
        }
    }
    private void FadingOptionsPanel_Loaded(object sender, RoutedEventArgs e)
    {
        //Initialize Fade In Animation
        DoubleAnimation fadeInDoubleAnimation = new DoubleAnimation();
        fadeInDoubleAnimation.From = 0;
        fadeInDoubleAnimation.To = 1;
        fadeInDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(.5));
        fadeInStoryboard = new Storyboard();
        fadeInStoryboard.Children.Add(fadeInDoubleAnimation);
        Storyboard.SetTargetName(fadeInDoubleAnimation, this.Name);
        Storyboard.SetTargetProperty(fadeInDoubleAnimation, new PropertyPath(Canvas.OpacityProperty));

        //Initialize Fade Out Animation
        DoubleAnimation fadeOutDoubleAnimation = new DoubleAnimation();
        fadeOutDoubleAnimation.From = 1;
        fadeOutDoubleAnimation.To = 0;
        fadeOutDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(.2));
        fadeOutStoryboard = new Storyboard();
        fadeOutStoryboard.Children.Add(fadeOutDoubleAnimation);
        Storyboard.SetTargetName(fadeOutDoubleAnimation, this.Name);
        Storyboard.SetTargetProperty(fadeOutDoubleAnimation, new PropertyPath(Canvas.OpacityProperty));
    }

I originally was using this code inside a usercontrol instead of a custom control before I found out that usercontrols don’t support content.

  • 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-14T01:43:21+00:00Added an answer on May 14, 2026 at 1:43 am

    One way is to override the corresponding OnXxx methods. For example:

    protected override void OnMouseEnter(MouseEventArgs e)
    {
      base.OnMouseEnter(e);
      if (IsFadeEnabled)
      {
        fadeInStoryboard.Begin(this);
      }
    }
    

    You can also add an event subscription in your constructor:

    public FadingOptionPanel()
    {
      this.MouseEnter += FadingOptionPanel_MouseEnter;
    }
    

    Note that for running a storyboard on an event, you can often do this without code-behind by using EventTriggers — but I’m not sure offhand whether an EventTrigger-based approach could be made to respect your IsFadeEnabled property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Keep in mind that I'm not looking for a list of current browsers to
I'm not looking for a full implementation, I'm more interested in how they do
I'm not looking for java-web-start, I'm looking for a thick-client application installation toolkit. I've
I'm not looking for the usual answer like Web-services. I'm looking for a light
I'm not looking for bug tracking, per se. But more like a build tool:
I'm not looking for a general discussion on if math is important or not
I am not looking for links to information on hashing. I am not looking
Please note - I am not looking for the right way to open/read a
I'm not looking so much for language-specific answers, just general models for implementing a
Maybe I'm not looking in the right places but I'd like to use SQL

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.