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

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your best bet is to use an operating system primitive… May 12, 2026 at 1:00 am
  • Editorial Team
    Editorial Team added an answer The idea of an interface is to represent a contract,… May 12, 2026 at 1:00 am
  • Editorial Team
    Editorial Team added an answer WebProxy proxy = new WebProxy("172.0.0.1:8080", true); proxy.Credentials = new NetworkCredential("user",… May 12, 2026 at 1:00 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.