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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:00:19+00:00 2026-05-11T09:00:19+00:00

I’m trying to animate the ScaleY property of a LayoutTransform based on a DataTrigger

  • 0

I’m trying to animate the ScaleY property of a LayoutTransform based on a DataTrigger bound to a boolean on my ViewModel class. The animation happens when the value is first seen to be false by the DataTrigger (when the application first starts) and when i first change it to true in a checkbox’s checked event but not when i set it to false in the same checkbox’s unchecked event.

A simplified version of what i’m doing is listed below.

The ViewModel class is very simple, containing a single boolean DependencyProperty called Selected.

    public class VM : DependencyObject {     public bool Selected     {         get { return (bool)GetValue(SelectedProperty); }         set { SetValue(SelectedProperty, value); }     }      // Using a DependencyProperty as the backing store for Selected.  This enables animation, styling, binding, etc...     public static readonly DependencyProperty SelectedProperty =         DependencyProperty.Register('Selected', typeof(bool), typeof(VM), new UIPropertyMetadata(false)); } 

The Window.xaml contains a button and a checkbox. When the checkbox is checked, i set the ViewModel’s ‘Selected’ property to true and false when it is unchecked. Here’s the code for both the xaml and it’s code-behind.

<Window x:Class='DataTriggers.Window1' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:y='clr-namespace:DataTriggers' Title='Window1' Height='300' Width='300'> <Window.Resources>     <y:VM x:Key='VM'/>      <Style TargetType='Button' x:Key='but'>         <Style.Triggers>             <DataTrigger Binding='{Binding Selected}' Value='False'>                 <DataTrigger.EnterActions>                     <BeginStoryboard>                         <Storyboard>                             <DoubleAnimation Duration='0:0:1'                                              To='0'                                              Storyboard.TargetProperty='(LayoutTransform).(ScaleTransform.ScaleY)'/>                         </Storyboard>                     </BeginStoryboard>                 </DataTrigger.EnterActions>             </DataTrigger>             <DataTrigger Binding='{Binding Selected}' Value='True'>                 <DataTrigger.EnterActions>                     <BeginStoryboard>                         <Storyboard>                             <DoubleAnimation Duration='0:0:1'                                              To='1'                                              Storyboard.TargetProperty='(LayoutTransform).(ScaleTransform.ScaleY)'/>                         </Storyboard>                     </BeginStoryboard>                 </DataTrigger.EnterActions>             </DataTrigger>         </Style.Triggers>     </Style> </Window.Resources> <StackPanel>              <Button Style='{StaticResource but}' DataContext='{StaticResource VM}'>         <Button.LayoutTransform>             <ScaleTransform></ScaleTransform>         </Button.LayoutTransform>             me             </Button>     <CheckBox Checked='CheckBox_Checked' Unchecked='CheckBox_Unchecked'/> </StackPanel> 

    public partial class Window1 : Window {     public Window1()     {         InitializeComponent();     }      private void CheckBox_Checked(object sender, RoutedEventArgs e)     {          VM vm = this.FindResource('VM') as VM;         vm.Selected = true;     }      private void CheckBox_Unchecked(object sender, RoutedEventArgs e)     {         VM vm = this.FindResource('VM') as VM;         vm.Selected = false;     } } 

I know that the DataTrigger fires when the property is false because if i change the DoubleAnimation to a simple Setter operating on the Opacity property then i see the correct results. So it would seem to be a problem with how I’m using the DoubleAnimation.

Any help would be appriciated.

  • 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. 2026-05-11T09:00:19+00:00Added an answer on May 11, 2026 at 9:00 am

    This is ODD behavior but i decided to refactor the ‘False’ case into the DataTrigger’s ExitActions like this –

    <DataTrigger Binding='{Binding Selected}' Value='True'>                 <DataTrigger.EnterActions>                     <BeginStoryboard>                         <Storyboard>                             <DoubleAnimation Duration='0:0:1'                                              To='1'                                              Storyboard.TargetProperty='(RenderTransform).(ScaleTransform.ScaleY)'/>                         </Storyboard>                     </BeginStoryboard>                 </DataTrigger.EnterActions>                 <DataTrigger.ExitActions>                     <BeginStoryboard>                         <Storyboard>                             <DoubleAnimation Duration='0:0:1'                                              To='0'                                              Storyboard.TargetProperty='(RenderTransform).(ScaleTransform.ScaleY)'/>                         </Storyboard>                     </BeginStoryboard>                 </DataTrigger.ExitActions>             </DataTrigger> 

    That works as intended. I don’t know what the difference is between the two cases but at least it’s an answer.

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

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.