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

  • SEARCH
  • Home
  • 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 6083123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:22:00+00:00 2026-05-23T11:22:00+00:00

I have this code: <UserControl.Resources> <Storyboard x:Key=OnMouseEnterToDocumentsMenu> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=(UIElement.Opacity) Storyboard.TargetName=Documents> <EasingDoubleKeyFrame KeyTime=0:0:0.2 Value=0.8/> </DoubleAnimationUsingKeyFrames>

  • 0

I have this code:

<UserControl.Resources>
    <Storyboard x:Key="OnMouseEnterToDocumentsMenu">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Documents">
            <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0.8"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
    <Storyboard x:Key="OnMouseLeaveFromDocumentsMenu">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Documents">
            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0.3"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
    <Storyboard x:Key="OnMouseEnterToPeopleMenu">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="People">
            <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0.8"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
    <Storyboard x:Key="OnMouseLeaveFromPeopleMenu">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="People">
            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0.3"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
    </Storyboard>
</UserControl.Resources>
<UserControl.Triggers>
    <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="Documents">
        <BeginStoryboard Storyboard="{StaticResource OnMouseEnterToDocumentsMenu}"/>
    </EventTrigger>
    <EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="Documents">
        <BeginStoryboard Storyboard="{StaticResource OnMouseLeaveFromDocumentsMenu}"/>
    </EventTrigger>
    <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="People">
        <BeginStoryboard Storyboard="{StaticResource OnMouseEnterToPeopleMenu}"/>
    </EventTrigger>
    <EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="People">
        <BeginStoryboard Storyboard="{StaticResource OnMouseLeaveFromPeopleMenu}"/>
    </EventTrigger>
    </EventTrigger>
</UserControl.Triggers>

Purpose

I’m animation a Menu. Menu elements are TextBlocks, I’m simulating a “Hover fading”.

Problem

The code I posted animates the opacity once the mouse enter or leave. I have another method (code behind) that sets to “1” the opacity of the menu element once the user clicks it on the menu (and load the appropriate user control on its respective container). I guess this method is working, BUT once the MouseLeave animation start it fades the opacity again no matter if that element was selected or not (If its opacity was 1 not 0.8).

Needs

Is there a way to specify that the MouseLeave trigger fires only when the Source Opacity is not 1. Or to execute the storyboard only if the TargetProperty is not 1.

Thanks.

PS

Is there a way to prevent code duplication given that the animation storyboards are the same (for focus and for fade) and that more menus will come. I duplicate it because I need to put the TargetName and is different but I suppose there is another “cleaner” way.

  • 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-23T11:22:01+00:00Added an answer on May 23, 2026 at 11:22 am

    This behavior is due to dependency property value precedence. I haven’t found a xamlish way to do this. But with code-behind here is how:

    • Subscribe to the storyboard’s completed event.
    • Look for the menuItems that has been selected and call BeginAnimation on it.
    • You can find more infomation on this here.

      private void Storyboard_Completed(object sender, EventArgs e) 
      { 
          foreach (var menuItem in this.file.Items) 
          { 
              var item = (MenuItem)menuItem; 
              if (item.IsChecked) 
              { 
                  item.BeginAnimation(UIElement.OpacityProperty, null); 
                  item.Opacity = 1; 
              } 
          } 
      } 
      

      I have looked for IsChecked to say if a menuItem is selected. Use your own methodology if this doesnt suit you.

    For question 2 add this to resources and you can get rid of all individual triggers and duplicate storyboards:

            <Window.Resources> 
        <Storyboard x:Key="HoverOn"> 
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)"> 
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.8"/> 
            </DoubleAnimationUsingKeyFrames> 
        </Storyboard> 
        <Storyboard x:Key="HoverOff" Completed="Storyboard_Completed"> 
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)"> 
                <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="0.3"/> 
            </DoubleAnimationUsingKeyFrames> 
        </Storyboard> 
        <Style TargetType="{x:Type MenuItem}"> 
            <Style.Triggers> 
            <EventTrigger RoutedEvent="Mouse.MouseEnter" > 
                <BeginStoryboard Storyboard="{StaticResource HoverOn}"/> 
            </EventTrigger> 
            <EventTrigger RoutedEvent="Mouse.MouseLeave"> 
                <BeginStoryboard Storyboard="{StaticResource HoverOff}"/> 
            </EventTrigger> 
            </Style.Triggers> 
        </Style> 
    </Window.Resources> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an UserControl and in it, a DropDownList. I'm using this code to
I have a UserControl, in the Resources section I have code like <Style TargetType={x:Type
I have a Button inside a UserControl : <UserControl.Resources> <ControlTemplate x:Key=ButtonTemplate TargetType={x:Type Button}> <ContentPresenter
I have the following scenario: <UserControl.Resources> <Style x:Key=NormalFontStyle> <Setter Property=Control.FontFamily Value={Binding MyFont}></Setter> </Style> <Style
I have created sample User Control RestrictedBox.xaml <UserControl.Resources> <Converters:EnumToVisibilityConverter x:Key=enumToVisConverter /> <Converters:EnumToVisibilityConverterReverse x:Key=enumToVisConverterReverse />
When I have: <UserControl.Resources> <Style x:Key=itemstyle TargetType={x:Type ListViewItem}> <EventSetter Event=MouseDoubleClick Handler=HandleDoubleClick /> <Setter Property=HorizontalContentAlignment
I have this code: namespace Test { public partial class SearchField : UserControl {
I have this code <div id=main style=background:#aaaaaa;float:left;height:160px;margin:5px;position:relative;display:block;width:630px;> <div id=1 class=item style=background:#ffaacc;float:left;width:200px;height:150px;margin:5px;position:absolute;left:0px;top:0px;> </div> <div id=2
I have this code : void Main() { System.Timers.Timer t = new System.Timers.Timer (1000);
I have this code for changing the image of a button: - (void)mouseEntered:(NSEvent *)event

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.