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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:28:19+00:00 2026-05-31T15:28:19+00:00

I have this xaml: <Canvas Width=75 Height=75> <Button x:Name=button Background=Olive Canvas.Left=0 Canvas.Top=0 Width=75 Height=75

  • 0

I have this xaml:

    <Canvas Width="75" Height="75">
        <Button x:Name="button" Background="Olive" Canvas.Left="0" Canvas.Top="0" Width="75" Height="75" Click="button_Click"/>
    </Canvas>

And this code behind:

    Private Sub button_Click(ByVal sender as Object, ByVal e as System.Windows.RoutedEventArgs)
        Canvas.SetTop(sender, -75)

        Dim sb1 As New Storyboard
        Dim da1 As New DoubleAnimationUsingKeyFrames
        da1.BeginTime = TimeSpan.FromSeconds(0)
        Storyboard.SetTargetName(da1, CType(sender, Button).Name)
        Storyboard.SetTargetProperty(da1, New PropertyPath(Canvas.TopProperty))

        Dim t1 As Double = Canvas.GetTop(sender)
        da1.KeyFrames.Add(New SplineDoubleKeyFrame(t1 + 75, TimeSpan.FromSeconds(0.2)))
        sb1.Children.Add(da1)

        BeginStoryboard(sb1)        
    End Sub

When I click the button the first time, it properly goes up by 75 and animates back to 0, but when I click the button again, it just animates down by 75. Why is it skipping the Canvas.SetTop line and goes straight to the animating part? And how to fix this?

  • 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-31T15:28:20+00:00Added an answer on May 31, 2026 at 3:28 pm

    Use this code (it is in C#) before Canvas.SetTop

    (sender as UIElement).BeginAnimation(Canvas.TopProperty, null);
    

    This will avoid that any animation overrides the value Canvas.TopProperty

    This link will help you

    http://joshsmithonwpf.wordpress.com/2008/08/21/removing-the-value-applied-by-an-animation/

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

Sidebar

Related Questions

given the following XAML code: <Canvas Name=MainView> <Canvas Name=TriangleElement Width=50 Height=50 Canvas.Left=110 Canvas.Top=100> <Canvas.RenderTransform>
hei, assume that i have this code: <StackPanel> <Canvas x:Name=canvas Height=400 Width=235> <Image x:Name=image
I have a xaml file with this code: <GridViewColumn x:Name=lvCol3 Header=Quantità Width=120> <GridViewColumn.CellTemplate> <DataTemplate>
So I have this Xaml inside a ListBox Item Template: <ListBox.ItemTemplate> <DataTemplate> <Grid Height=22
I have this code in a xaml file now in a event handler code
I have something like this in my xaml: <Grid> <Image Name=image Source=../../Images/DefaultImage.png HorizontalAlignment=Stretch VerticalAlignment=Stretch></Image>
I need to define canvas width and height in centimeters, so basically I have
I have a rectangle in my XAML and want to change its Canvas.Left property
i have this code: <Window x:Class=WpfApplication8.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=350 Width=525> <Grid> <ScrollViewer Background=#FFADB9CD
Let's say I have this xaml code : <Window xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml> <Canvas> <Rectangle Name=papan

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.