/// <summary> /// TargetSizeProperty property changed handler. /// </summary> /// <param name="dependencyObject">ExpandableContentControl that changed its TargetSize.</param> /// <param name="e">Event arguments.</param> private static void OnTargetSizePropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { ExpandableContentControl source = (ExpandableContentControl)dependencyObject; Size value = (Size)e.NewValue; // recalculate percentage based on this new targetsize. // for instance, percentage was at 1 and width was 100. Now width was changed to 200, this means // that the percentage needs to be set to 0.5 so that a reveal animation can be started again. // We are essentially trying to re-evaluate the percentage property based on another property having changed, // which is exactly what the coerce functionality of dependency properties is for source.RecalculatePercentage(double.NaN); }
/// <summary> /// ContentTargetSizeProperty property changed handler. /// </summary> /// <param name="dependencyObject">AccordionItem that changed its ContentTargetSize.</param> /// <param name="e">Event arguments.</param> private static void OnContentTargetSizePropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { AccordionItem source = (AccordionItem)dependencyObject; Size targetSize = (Size)e.NewValue; if (!source.allowedToWriteContentTargetSize) { // revert to old value source.ContentTargetSize = (Size)e.OldValue; throw new InvalidOperationException(AccordionResources.AccordionItem_InvalidWriteToContentTargetSize); } // Pass the value to the expandSite // This is done explicitly so an animation action can be scheduled // deterministicly. ExpandableContentControl expandSite = source.ExpandSite; if (expandSite != null && !expandSite.TargetSize.Equals(targetSize)) { expandSite.TargetSize = targetSize; if (source.IsSelected) { if (source.ParentAccordion != null && source.ParentAccordion.IsResizing) { // if the accordion is resizing, this item should snap immediately expandSite.RecalculatePercentage(1); } else { // otherwise schedule the resize source.Schedule(AccordionAction.Resize); } } } }