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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:34:57+00:00 2026-05-31T19:34:57+00:00

Im trying to toggle an animation on height when a button Show Details/Hide Details

  • 0

Im trying to toggle an animation on height when a button “Show Details”/”Hide Details” is clicked and then back to its initial value when the button is clicked again.

I have a DataControls:DataForm with predefined style to start with, and I want the “Height”-property to animate to a larger value when the button is clicked.

The DataControl:Dataform looks like this.

<DataControls:DataForm x:Name="DataEdit"
                           Grid.Row="1"
                           ItemsSource="{Binding}"
                           Style="{DynamicResource CommonDataFormStyle}"
                           ContentLoaded="OnContentLoaded" 
                           Height="150">

The button itself is inside the DataForm like this.

<DataControls:DataForm.ReadOnlyTemplate>
     <DataTemplate>          
         <Grid>
            <Grid.RowDefinitions>...
               <StackPanel Grid.Column="0" Grid.Row="0">            
                  <Button Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl} }, Path=DataContext.ToggleDetailsCommand, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" x:Name="ToggleDetailsButton"                                      
                             Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl} }, Path=DataContext.ToggleDetailsButtonText}"/> 
...

I have only gotten this to work by usina a label called “Show Details” and an eventtrigger for RoutedEvent=”Label.MouseLeftButtonDown” on one label to expand the details.
And then have another label called “Hide Details” to togge the animation back again.

I have alsto tried puting this style on the button and with datatriggers trying to toggle the animation. This, however, does only animate the height of the button regardless of the StoryBoard.Target=”{Binding ElementName=DataEdit}” attribute.

<Style TargetType="{x:Type Button}" x:Key="ExpandDetailsStyle" >            
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl} }, Path=DataContext.IsOpened}" Value="true">
                <DataTrigger.EnterActions>
                    <StopStoryboard BeginStoryboardName="EndAnimation" />
                    <BeginStoryboard Name="NewAnimation">
                        <Storyboard>
                            <DoubleAnimation Storyboard.Target="{Binding ElementName=DataEdit}" Storyboard.TargetProperty="Height" From="150" To="300" Duration="0:0:0.1" />
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
                <DataTrigger.ExitActions>

                </DataTrigger.ExitActions>

            </DataTrigger>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl} }, Path=DataContext.IsOpened}" Value="false">
                <DataTrigger.EnterActions>
                    <StopStoryboard BeginStoryboardName="NewAnimation" />
                    <BeginStoryboard Name="EndAnimation">
                        <Storyboard>
                            <DoubleAnimation Storyboard.Target="{Binding ElementName=DataEdit}" Storyboard.TargetProperty="Height" From="300" To="150" Duration="0:0:0.1" />
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
            </DataTrigger>

        </Style.Triggers>
    </Style>

Also I’m fairly new to WPF so forgive me if I left something out here.
Im unable to put a new custom style on the DataForm since it is already using a common style, it wouldnt let me use the “BasedOn” attribute either.

The closest I’ve got is the animation of the button height, if I only could get it to animate the DataForm height property instead.

Thanks in advance

  • 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-31T19:34:58+00:00Added an answer on May 31, 2026 at 7:34 pm

    After quite some hours looking around I found a simple solution for my, what I thought, complex problem.

    <UserControl.Resources>
        <Storyboard x:Key="ExpandDetails">
            <DoubleAnimation Storyboard.TargetProperty="Height"                                                     
                                                        Storyboard.TargetName="DataEdit"
                                                        From="120" To="230" Duration="0:0:0.05" />
        </Storyboard>
        <Storyboard x:Key="CollapsDetails">
            <DoubleAnimation Storyboard.TargetProperty="Height"                                                     
                                                    Storyboard.TargetName="DataEdit"
                                                    From="230" To="120" Duration="0:0:0.05" />
        </Storyboard>                
        <Style TargetType="{x:Type ToggleButton}" x:Key="ToggleButtonStyle">
            <Setter Property="Content" Value="Show Details"/>
            <Style.Triggers>
                <Trigger Property="IsChecked" Value="true">
                    <Setter Property="Content" Value="Hide Details"/>
                </Trigger>
            </Style.Triggers>
        </Style>    
    </UserControl.Resources>
    
    
    <UserControl.Triggers>
        <EventTrigger RoutedEvent="ToggleButton.Checked" SourceName="DetailsToggleButton">
            <BeginStoryboard Storyboard="{StaticResource ExpandDetails}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="ToggleButton.Unchecked" SourceName="DetailsToggleButton">
            <BeginStoryboard Storyboard="{StaticResource CollapsDetails}"/>
        </EventTrigger>
    </UserControl.Triggers>
    

    I couldnt figure out how to have the button inside the data form in this case because of the scope it would be in it couldnt find the “DataEdit” dataform with any of my known binding techniques.

    So this had to be placed outside the DataForm.

    <ToggleButton x:Name="DetailsToggleButton" Style="{StaticResource ToggleButtonStyle}" />
    

    Sources to my solution:
    WPF: how to fire an EventTrigger (or Animation) when binding changes?
    WPF – Changing the content of a ToggleButton when checked

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

Sidebar

Related Questions

I am trying to hide/show/toggle a div when a button is clicked. I am
I'm trying to toggle (hide/show) a table when clicking a button which is located
Trying to make a simple toggle menu, and I can't seem to hide/show the
I'm trying to toggle hide/show on all divs with the same class. I have
I am trying to show/hide (via a toggle mechanism) only certain rows in my
Trying to make a toggle button that hides/shows the right window/pane. Here is a
I'm trying to get #content to toggle, but it won't work. $(button).click(function () {
I'm trying to basically make a toggle button to change the background color of
I am trying to show and hide an inline element (eg a span) using
I am trying to toggle the parent <li> and <button> styles. Here my code

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.