C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C# Expert!

Join 307,136 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,895 people online right now. Registration is fast and FREE... Join Now!




Animate a Panel

 

Animate a Panel, How to animate a panel containing multiple UIElements

chipshop

1 Jul, 2009 - 12:22 PM
Post #1

New D.I.C Head
*

Joined: 18 Jun, 2009
Posts: 4

Hello,

This should be an easy one to someone who is familiar with animations in C# and WPF. I have a grid panel defined in WPF which contains an ink canvas and some buttons. This gives me the layout I want for this control - but I would like to slide it on and off the screen when the user needs it, using the code behind file to control it from another button. I can't animate the grid because it doesn't have a margin or center dependency property. What should I do?

Many Thanks,

Ricky

biggrin.gif

Update:

okay so I've managed to figure out that I'll need to add a custom DependencyProperty and then animate that. The margin property with then be update by Binding with the DP.

So far I've got:

CODE

<Grid x:Name="dschg_uc" Margin="{Binding Margindp}" >

in the XAML

and:
CODE

    public class Test : Animatable
    {
        public static readonly DependencyProperty MyDoubleProperty = DependencyProperty.Register("Margindp", typeof(double), typeof(SurfaceWindow1));
        public double Margindp
        {
            get
            {
                return (double)GetValue(MyDoubleProperty);
            }
            set
            {
                SetValue(MyDoubleProperty, value);
            }
        }
        protected override Freezable CreateInstanceCore()
        {
            throw new NotImplementedException();
        }

dschg_uc.BeginAnimation(Test.MyDoubleProperty, positionAnimation);

in the code.

I know it's not right (because it's not working). What have I done wrong?

Update2: I managed to get what I want by wrapping the grid in a user control which does have a margin dependency property and using a thicknessanimation. And I learned some things about DPs and binding along the way.

Thanks!

This post has been edited by chipshop: 1 Jul, 2009 - 02:57 PM

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 03:03PM

Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month