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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:47:18+00:00 2026-05-23T15:47:18+00:00

I am having an issue when using EventTriggers. I have two buttons and two

  • 0

I am having an issue when using EventTriggers. I have two buttons and two EventTriggers that I want to listen for Click events from those buttons, then the triggers should start a StoryBoard which animates the height of a control.
I have no problem with starting the StoryBoards, I simply have a problem with specifying the SourceName of the EventTrigger:

<UserControl x:Class="MyWindow"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             >

    <UserControl.Resources>
        <Storyboard x:Key="GrowPanel1">
            <DoubleAnimation To="400" Duration="0:0:0.75" Storyboard.TargetName="Panel1" Storyboard.TargetProperty="Height" />
        </Storyboard>
        <Storyboard x:Key="GrowPanel2">
            <DoubleAnimation To="400" Duration="0:0:0.75" Storyboard.TargetName="Panel2" Storyboard.TargetProperty="Height" />
        </Storyboard>
    </UserControl.Resources>

    <Grid >
        <Grid.Triggers>
            <EventTrigger RoutedEvent="Button.Click" SourceName="TriggerElement1" >
                <EventTrigger.Actions>
                    <BeginStoryboard Storyboard="{StaticResource GrowPanel1}"  />
                </EventTrigger.Actions>
            </EventTrigger>
            <EventTrigger RoutedEvent="Button.Click"  SourceName="TriggerElement2" >
                <EventTrigger.Actions>
                    <BeginStoryboard Storyboard="{StaticResource GrowPanel2}"  />
                </EventTrigger.Actions>
            </EventTrigger>
        </Grid.Triggers>
        <Border BorderBrush="HotPink" BorderThickness="2">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>


                <ContentPresenter Panel.ZIndex="20" Grid.Column="1" >
                    <ContentPresenter.Content>
                        <StackPanel Orientation="Horizontal">
                            <Button x:Name="TriggerElement2" Background="BurlyWood"  Width="30" Height="30" VerticalAlignment="Top" />
                            <Button x:Name="TriggerElement1" Background="Chartreuse"  Width="30" Height="30" VerticalAlignment="Top" />
                        </StackPanel>
                    </ContentPresenter.Content>
                </ContentPresenter>

                <Grid Grid.Column="0" Grid.ColumnSpan="2">
                    <my1:TreeViewNav Name="Panel1" Height="0" VerticalAlignment="Top" />
                    <my:ListViewNav x:Name="Panel2" Height="0" VerticalAlignment="Top" />
                </Grid>
            </Grid>
        </Border>
    </Grid>
</UserControl>

With this I get a run time error:

The most likely causing exception was was: ‘System.Windows.Markup.XamlParseException: ‘Initialization of ‘System.Windows.Controls.Grid’ threw an exception.’ Line number ’23’ and line position ‘6’. —> System.ArgumentException: Cannot find a FrameworkElement with Name ‘TriggerElement1’.
at System.Windows.FrameworkElement.FindNamedFrameworkElement(FrameworkElement startElement, String targetName)
at System.Windows.EventTrigger.ProcessOneTrigger(FrameworkElement triggersHost, TriggerBase triggerBase)
at System.Windows.EventTrigger.ProcessTriggerCollection(FrameworkElement triggersHost)
at System.Windows.FrameworkElement.TryFireInitialized()
at System.Windows.FrameworkElement.EndInit()
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.InitializationGuard(XamlType xamlType, Object obj, Boolean begin)
— End of inner exception stack trace —

Removing the EventTrigger SourceName property fixes the error, but I need to start different StoryBoards depending on which button is clicked. So as far as I know I need to use the SourceName.

Why can’t WPF find my Button called TriggerElement1? I thought RoutedEvents get bubbled up the visual tree, so as long as the trigger is at a high enough level it should have no naming problems? It has no problem finding the StoryBoard.Target called Panel1. Have I taken the right approach to get two buttons to trigger different storyboards?

  • 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-23T15:47:19+00:00Added an answer on May 23, 2026 at 3:47 pm

    Since your button “TriggerElement1” is inside a ContentPresenter App is unable to locate the button at initalization. Because contentpresentor content will be rendered at runtime.

    I made few changes to your code which is working fine now… hope this will solve your problem.

    <UserControl x:Class="WpfApplication1.MyWindow"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008">
    
        <UserControl.Resources>
            <Storyboard x:Key="GrowPanel1">
                <DoubleAnimation To="400" Duration="0:0:0.75" Storyboard.TargetName="Panel1" Storyboard.TargetProperty="Height" />
                <DoubleAnimation To="0" Duration="0:0:0.75" Storyboard.TargetName="Panel2" Storyboard.TargetProperty="Height" />
            </Storyboard>
            <Storyboard x:Key="GrowPanel2">
                <DoubleAnimation To="400" Duration="0:0:0.75" Storyboard.TargetName="Panel2" Storyboard.TargetProperty="Height" />
                <DoubleAnimation To="0" Duration="0:0:0.75" Storyboard.TargetName="Panel1" Storyboard.TargetProperty="Height" />
            </Storyboard>
        </UserControl.Resources>
        <Grid>
            <Border BorderBrush="HotPink" BorderThickness="2">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
    
                    <StackPanel Orientation="Horizontal" Grid.Column="1" >
                        <Button x:Name="TriggerElement2" Background="BurlyWood"  Width="30" Height="30" VerticalAlignment="Top">
                            <Button.Triggers>
                                <EventTrigger RoutedEvent="Button.Click">
                                    <EventTrigger.Actions>
                                        <BeginStoryboard Storyboard="{StaticResource GrowPanel2}"  />
                                    </EventTrigger.Actions>
                                </EventTrigger>
                            </Button.Triggers>
                        </Button>
                        <Button x:Name="TriggerElement1" Background="Chartreuse"  Width="30" Height="30" VerticalAlignment="Top" >
                            <Button.Triggers>
                                <EventTrigger RoutedEvent="Button.Click">
                                    <EventTrigger.Actions>
                                        <BeginStoryboard Storyboard="{StaticResource GrowPanel1}"  />
                                    </EventTrigger.Actions>
                                </EventTrigger>
                            </Button.Triggers>
                        </Button>
                    </StackPanel>
    
                    <Grid Grid.Column="0" Grid.ColumnSpan="2" VerticalAlignment="Bottom">
                        <Grid Name="Panel1" Height="0" VerticalAlignment="Top" Background="Red"/>
                        <Grid x:Name="Panel2" Height="0" VerticalAlignment="Top" Background="Blue"/>
                    </Grid>
                </Grid>
            </Border>
        </Grid>
    </UserControl>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having an issue removing %3Cbr+%2F%3E from my string using the preg_replace function.
having an issue using a NSMutableArray; In my implementation file applicationDidFinishLaunching method I have
I am having an issue with the using jqGrid with JSON data returned from
I’m having an issue using ADFS2 to secure a back-end WCF service that is
Have been having an issue sine using the HABTM relationship in models instead of
I am having an issue using BinaryFormatter.Serialize. I have this generic extension method to
i'm having an issue using C# inserting multiple rows into a MySQL database, have
I'm having a design issue using jQuery FadeIn on Internet Explorer: I have a
I'm having a strange issue when using subprocess.Popen.communicate(). For background, I want to execute
Im having an issue using Java script to create a table that displays an

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.