Every time when you want to create a pane that can collapse or expand, you have to write either a Storyboard in xaml or some other animation logic. This can be a tedious task and has many pitfalls. Some of them being - Change in width of the pane requires rewiring of the storyboard.
- Consistency in the collapse/expand duration of the pane.
- Flexibility in changing the pane from vertical to horizontal.
To solve all of these and many more problems that may arise we need to build a custom PaneManager that will do this for us when required.
At first we must create a class in your Silverlight application, lets call it PaneManager, with the following members
public class PaneManager
{
#region Public Members
public TimeSpan Interval { get; set; }
public double Increment { get; set; }
public double MinValue { get; set; }
public double MaxValue { get; set; }
public Grid Grid { get; set; }
public int Index { get; set; }
public GridUnitType GridUnitType { get; set; }
public Orientation Alignment { get; set; }
#endregion
}
Let us go over each member in detail.
- Interval - This defines the duration to wait between successive calls to make the pane transition.
- Increment - This is the value by which the pane's width or height must change.
- MinValue - This defines the minimum threshold of the pane's width or height.
- MaxValue- This defines the maximum threshold of the pane's width or height.
- Grid - This is the parent Grid that contains the desired pane.
- Index - This is the index of the row or column containing the pane.
- GridUnitType - this is the unit of measurement of the Grid's row/column.
- Alignment - This specifies whether the pane transition is to be done on a row or column.
We will also need to add the following members and events to the PaneManager class
#region Private Members
private Storyboard _storyboard = new Storyboard();
#endregion
#region Public Event
public event EventHandler Completed
{
add { _storyboard.Completed += value; }
remove { _storyboard.Completed -= value; }
}
#endregion
We have until now created the basic structure of the PaneManager without adding any functionality as such. To make this class usable,