Sunday, March 29, 2009

We continue our exploration of Accordion. This time we’ll take a look at some of the template parts, namely ExpandableContentControl. See part 1 and part 2 if you didn’t yet.

ExpandableContentControl

This control is part of AccordionItem and is used to display the content of an accordionItem. It sits in the Primitives namespace, which means it will be used primarily as a part of a template. It solves an important problem: being able to resize (expand/contract) a piece of content, without triggering resize actions on the content itself. With that I mean: if your AccordionItem would use a Grid or a DockPanel as it’s content and I would just be animating the width or the height, you would see the panel changing as it tries to keep up with the new sizes. Ofcourse, that would not be the case if you had set an explicit width or height to the panel, but AccordionItem does not force you to do so.So, during the resize of our AccordionItem, I don’t want the content to have to resize.

Furthermore, it would be nice to make it really easy for you to determine how the animation should look like. Do you want a gradual easein/out, a bump or something different altogether? I want to be able to design my animation in Blend, using the nifty keyspline features!

I accomplish the above goals by throwing in a ScrollViewer and defining a DependencyProperty: Percentage.

ScrollViewer allows Accordion to just determine the size the item will eventually be (after expand action) and set it only once. At that moment the content of the scrollviewer is going to resize itself accordingly. Then, as we animate the width or height of the scrollviewer, its content is none-the-wiser. Hence, no ugly resize actions going on.

Making the actual animation be easily defined inside of Blend, is done by the above-mentioned Percentage DP.
Accordion only determines the size the AccordionItem will eventually be, I call it the TargetSize. ExpandableContentControl will calculate and set its actual size using to the following simple function: actualsize = percentage * TargetSize.

Accordion also triggers a visualstate called either Expanded or Contracted on AccordionItem. Those animate the percentage property on ExpandableContentControl. See this Xaml in the template of AccordionItem:

   62 <vsm:VisualState x:Name="Collapsed">

   63     <Storyboard>

   64         <DoubleAnimationUsingKeyFrames

   65             BeginTime="00:00:00"

   66             Storyboard.TargetName="ExpandSite"

   67             Storyboard.TargetProperty="(ExpandableContentControl.Percentage)">

   68             <SplineDoubleKeyFrame

   69                 KeyTime="00:00:00.3"

   70                 KeySpline="0.2,0,0,1"

   71                 Value="0" />

   72         </DoubleAnimationUsingKeyFrames>

   73     </Storyboard>

   74 </vsm:VisualState>

   75 <vsm:VisualState x:Name="Expanded">

   76     <Storyboard>

   77         <DoubleAnimationUsingKeyFrames

   78             BeginTime="00:00:00"

   79             Storyboard.TargetName="ExpandSite"

   80             Storyboard.TargetProperty="(ExpandableContentControl.Percentage)">

   81             <SplineDoubleKeyFrame

   82                 KeyTime="00:00:00.3"

   83                 KeySpline="0.2,0,0,1"

   84                 Value="1" />

   85         </DoubleAnimationUsingKeyFrames>

   86     </Storyboard>

   87 </vsm:VisualState>

This makes it possible to design your animation at the correct level (AccordionItem) and makes it a very design friendly experience, because Blend allows you to edit keysplines as follows:

image

(SL3 is adding a nice collection of other spline types that makes elastic AccordionItems even easier!)

I’ll discuss the remaining points of interest.

RevealMode

Since I expose one property (Percentage) for you to animate, the control needs to know whether that responds to the vertical or horizontal direction. Thus, AccordionItem will set the correct RevealMode, corresponding to its own ExpandDirection.

TargetSize

Already mentioned, setting the TargetSize will set the size of the ScrollViewer. It will also recalculate the percentage. Let’s say I have an item that has a height of 100. Now another item is collapsed, so the Accordion decides the remaining items should have a height of 160. The percentage that was once at 1 is recalculated to be 0.625.
This way we don’t have to restart the full animation, but we can just resize nicely.


I hope that helps understanding this vital piece of the template. In the future, I will either remove it (if the outlined problems can be solved more gracefully in another way) or expose the style of ExpandableContentControl in AccordionItem, so it can be more easily styled.

Thursday, April 02, 2009 7:29:10 PM (Romance Standard Time, UTC+01:00)
Ruurd, you promised me to show me how to retemplate the accordion so that the accordion item's content occupies the entire space of the accordion item. I discovered some Accordion issues. I created a post on the Silverlight forum: http://silverlight.net/forums/p/84223/196252.aspx#196252
I am struggling with the accordion for a week now and I have to make a decision whether the control suits my needs. Your help is appreciated.
Michel
Friday, April 03, 2009 6:52:03 AM (Romance Standard Time, UTC+01:00)
Michel, I'm sorry I haven't gotten to it yet. I have received your email and will be look at it this weekend.
Ruurd
Friday, April 03, 2009 7:22:03 AM (Romance Standard Time, UTC+01:00)
Ruurd, I think you mistake me for Mikhail. I didn't send you an email. I created a post on the Silverlight forum: http://silverlight.net/forums/p/84223/196252.aspx#196252
Thanks in advance.
Michel
Friday, April 03, 2009 5:10:31 PM (Romance Standard Time, UTC+01:00)
whoops, quite right!
Ruurd
Monday, April 06, 2009 2:12:50 AM (Romance Standard Time, UTC+01:00)
@Michel,

I read the post and the issue is about the same problem Mikhail was struggling with. Thank you for opening the workitems, we'll start tweaking the experience according to your feedback!
Ruurd
Tuesday, April 07, 2009 11:32:43 AM (Romance Standard Time, UTC+01:00)
Thanks for the response. I don't mean to push, but it is important for me to know when the solution will be available. Is it in the next toolkit release or will you provide a template in the mean time? My project forces me to make a decision whether to wait or to implement something myself. Thanks in advance.
Michel
Friday, April 17, 2009 11:21:30 AM (Romance Standard Time, UTC+01:00)
Ruurd, I am still waiting for a response from you. Thanks in advance.
Michel
Saturday, April 18, 2009 3:40:06 AM (Romance Standard Time, UTC+01:00)
Sorry, I thought I had already replied. My bad.

I can't give you a date on our next release, sorry.
I am trying to get an intermediate release happening, maybe source only. However, no decisions on this have been made.

If you are going to implement something yourself, do consider just grabbing the source and modifying it to suit your needs.

Hope that that helps.
Ruurd
Thursday, January 28, 2010 6:39:39 AM (Romance Standard Time, UTC+01:00)
Hi
I have used expander control which contains set of controls
i.e.expander containing grid with three rows
1st row i have a slider
2nd row contains a textbox
3rd row contains a two textblocks
In my expander I have added ExpandableContentControl to show the appropriate animation
now I have a functionality to hide and show the third row on a button click

I am able to do that but the problem is my contents inside the expander shows space of the third row when we hide
but when i click on expander i.e. my expanded event all the controls get properly placed and when i show the third row it gets cut but again on expanded event of the expander all are properly placed

So please help me as soon as possible
Thanks
Nidhi
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):