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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:53:56+00:00 2026-06-01T11:53:56+00:00

The problem I’m having is that if I base a style on a second

  • 0

The problem I’m having is that if I base a style on a second style that contains a storyboard, then there is an exception in the Trigger.ExitAction.

  • If I mouse over either of the rectangles in the demo below then the storyboard will run and the rectangles change colour.
  • When the mouse leaves the red rectangle with style=’rectStyle’ the storyboard is removed.
  • When the mouse leaves the blue rectangle (which uses the derived style) I get this exception:

    InvalidOperationException:
    ‘MouseOverStoryboard’ name cannot be found in the name scope of ‘System.Windows.Style’.

So:

  • Is it valid to have a storyboard in a base style?
  • Is there a more explicit way of referring to the BeginStoryboardName so that this error doesn’t occur?
  • Any other suggestions?

In the end what I’m trying to achieve re-use a style containing triggers and storyboards in several other styles.

Here’s some simple code that demonstrates the problem:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>

    <Grid.Resources>
        <Style x:Key="rectStyle" TargetType="{x:Type Rectangle}">
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Trigger.EnterActions>
                        <BeginStoryboard x:Name="MouseOverStoryboard">
                            <Storyboard>
                                <ColorAnimation To="PaleGoldenrod" 
                                   Storyboard.TargetProperty="(Fill).(Color)" 
                                   Duration="0:0:1"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </Trigger.EnterActions>
                    <Trigger.ExitActions>
                        <StopStoryboard BeginStoryboardName="MouseOverStoryboard"/>
                    </Trigger.ExitActions>
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="rectStyle2" TargetType="{x:Type Rectangle}" 
               BasedOn="{StaticResource rectStyle}"/>
    </Grid.Resources>

    <Rectangle Grid.Row="0" Width="100" Height="100" Fill="Red" 
               Style="{StaticResource rectStyle}" />
    <Rectangle Grid.Row="1" Width="100" Height="100" Fill="Blue" 
               Style="{StaticResource rectStyle2}" />
</Grid>
  • 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-06-01T11:53:57+00:00Added an answer on June 1, 2026 at 11:53 am

    Your best bet is to steer clear of derived styles if you want to include StopStoryboard. There are actually 2 instances of the style and the scope is wrong for the derived style. I believe this is by design. You could abstract that storyboard out to an outer scope in the resources and duplicate the triggers in both styles, referencing the Storyboard by StaticResource. It may not solve your problem since you may have a specific requirement for derived styles, but I don’t think you have a choice unfortunately.

    Because you cannot inherit from a base style at all if you want to use StopStoryboard you’d have to do something like this:

    <Grid>
    <Grid.RowDefinitions>
      <RowDefinition/>
      <RowDefinition/>
    </Grid.RowDefinitions>
    <Grid.Resources>
      <Storyboard x:Key="mouseOver">
        <ColorAnimation
          AutoReverse="True"
          Duration="0:0:1"
          RepeatBehavior="Forever"
          Storyboard.TargetProperty="(Fill).(Color)"
          To="PaleGoldenrod"/>
      </Storyboard>
      <Style x:Key="rectStyle" TargetType="{x:Type Rectangle}">
        <Style.Triggers>
          <Trigger Property="IsMouseOver" Value="True">
            <Trigger.EnterActions>
              <BeginStoryboard x:Name="MouseOverStoryboard" Storyboard="{StaticResource mouseOver}"/>
            </Trigger.EnterActions>
            <Trigger.ExitActions>
              <StopStoryboard BeginStoryboardName="MouseOverStoryboard"/>
            </Trigger.ExitActions>
          </Trigger>
        </Style.Triggers>
      </Style>
      <Style x:Key="rectStyle2" TargetType="{x:Type Rectangle}">
        <Style.Triggers>
          <Trigger Property="IsMouseOver" Value="True">
            <Trigger.EnterActions>
              <BeginStoryboard x:Name="MouseOverStoryboard1" Storyboard="{StaticResource mouseOver}"/>
            </Trigger.EnterActions>
            <Trigger.ExitActions>
              <StopStoryboard BeginStoryboardName="MouseOverStoryboard1"/>
            </Trigger.ExitActions>
          </Trigger>
        </Style.Triggers>
      </Style>
    </Grid.Resources>
    <Rectangle
      Width="100"
      Height="100"
      Grid.Row="0"
      Fill="Red"
      Style="{StaticResource rectStyle}"/>
    <Rectangle
      Width="100"
      Height="100"
      Grid.Row="1"
      Fill="Blue"
      Style="{StaticResource rectStyle2}"/>
    

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

Sidebar

Related Questions

Problem: I'm working on a website where there is a dial that displays a
Problem (simplified to make things clearer): 1. there is one statically-linked static.lib that has
Problem: I am having trouble implementing a recursive image lazy load in all relevant
Problem When working with MasterPages, a common irritation I run into is that script
Problem: to show that a Not-SO-page has been discussed in SO when you at
Problem PHP session in different folder. I have problem with PHP session. There are
Problem: I have 2 classes, DB class and a User class, that will work
Problem is like this: Suppose there are records in dataTable with FruitType as A
Problem Description: Multi-player Game that works over the some kind of network, in game
Problem is like this: I have two winapi application's. There is only one way

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.