How to animate an edit box to slide in and out using Expression Blend
Ok…so I created a simple WPF and MVVM application called My Friends. This is just a simple applications, the main goal was not to create a My Friend app, but do demonstrate how to make an edit box slide in an out.
The application is too big to give you step by step instructions to create the whole application, so instead, I am going to make it available for download and then tell you how to see the changes.
- Download and extract the solution from the link below:
- Open the project in Expression Blend (not Visual Studio).
- Get to know the Application. (Ok, I guess you could do this part in Visual Studio…but the intent is to learn an Expression Blend feature.)
Check out the Person and PersonCollection classes in the Model folder.
Check out the Views and the corresponding ViewModels and look at the binding statements.
The MVVM folder has some standard MVVM classes, that if you know MVVM you should be familiar with.
The business has an XML Serialization helper class.
The data folder contains an XML that is serialized from the PersonCollection class.
- In Expression Blend, open the View\FriendListView.xaml.
- In the Objects and Timeline tab, get to know the assets that are being used. (I think they are all standard assets. I don’t think I am using anything that doesn’t come with .NET and Expression Blend by default.)
- In the Objects and Timeline tab, specifically look at the PersonDetailsView object.
Notice it is behind the FriendList.
This is the edit box that is animated and it will slide to the right when you click edit.
- Go to the States tab.
Look a the State group that is created. There are two groups: EditFriendOpenState and EditFriendClosedState. The names should be obvious.
Notice the Transition duration is set to .5 and notice the Easing function.
- There is a behavior or action called GoToStateAction that was dragged over the Edit button and configured to change the state to EditFriendOpenState.
- The GoToStateAction was also dragged over the X button on the edit page and configured to change the state toEditFriendClosedState.
- Build the application and see how the state changes and how it uses the Easing function for .5 seconds to slide the edit field out.
Here is a sample image:
Anyway, I hope you find this a fun sample application to learn with.
This project is also an example of:
- Basic C#
- Xml Serialization
- MVVM (including ICommand and RelayCommand with buttons)
- Using Data Converters (as one converter is used)
Exercises for further learning:
- There is a comment in the View\FriendListView.xaml that uses LINQ, but there is a reason LINQ wasn’t used, can you determine the reason.
- What would you have to do to use LINQ and make the application work?
- There is an Age property that was left commented out. Uncomment it, make it read-only and make it provide the correct number in years based on the Birthday.