/// <summary> /// ExpandDirectionProperty <see cref="PropertyChangedCallback"/> call back static /// function. /// This function validates the new value before calling virtual function /// OnExpandDirectionChanged. /// </summary> /// <param name="dependencyObject">Expander object whose ExpandDirection property is /// changed.</param> /// <param name="e">DependencyPropertyChangedEventArgs which contains /// the old and new values.</param> private static void OnExpandDirectionPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { AccordionItem ctrl = (AccordionItem)dependencyObject; ExpandDirection oldValue = (ExpandDirection)e.OldValue; ExpandDirection newValue = (ExpandDirection)e.NewValue; if (!ctrl.allowedToWriteExpandDirection) { // revert to old value ctrl.ExpandDirection = oldValue; string message = string.Format( CultureInfo.InvariantCulture, AccordionResources.AccordionItem_InvalidWriteToExpandDirection, newValue); throw new InvalidOperationException(message); } // invalid value. This check is not of great importance anymore since // the previous check should catch all invalid sets. if (newValue != ExpandDirection.Down && newValue != ExpandDirection.Left && newValue != ExpandDirection.Right && newValue != ExpandDirection.Up) { // revert to old value ctrl.ExpandDirection = oldValue; string message = string.Format( CultureInfo.InvariantCulture, AccordionResources.Expander_OnExpandDirectionPropertyChanged_InvalidValue, newValue); throw new ArgumentException(message, "e"); } if (ctrl.ExpandSite != null) { // Jump to correct percentage after a direction change ctrl.ExpandSite.RecalculatePercentage(ctrl.IsSelected ? 1 : 0); } ctrl.UpdateVisualState(true); }
/// <summary> /// SelectedProperty <see cref="PropertyChangedCallback"/> static function. /// </summary> /// <param name="dependencyObject">Expander object whose Expanded property is changed.</param> /// <param name="e">DependencyPropertyChangedEventArgs which contains the /// old and new values.</param> private static void OnIsSelectedPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { AccordionItem ctrl = (AccordionItem)dependencyObject; bool isSelected = (bool)e.NewValue; // Not allowed to change the IsSelected state when locked. if (ctrl.IsLocked && ctrl.isSelectedNestedLevel == 0) { ctrl.isSelectedNestedLevel++; ctrl.SetValue(IsSelectedProperty, e.OldValue); ctrl.isSelectedNestedLevel--; throw new InvalidOperationException(AccordionResources.AccordionItem_OnIsSelectedPropertyChanged_InvalidChange); } if (ctrl.isSelectedNestedLevel == 0) { Accordion parent = ctrl.ParentAccordion; if (parent != null) { if (isSelected) { parent.OnAccordionItemSelected(ctrl); } else { parent.OnAccordionItemUnselected(ctrl); } } if (isSelected) { ctrl.OnSelected(); } else { ctrl.OnUnselected(); } } }
/// <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); } } } }
/// <summary> /// ExpandableContentControlStyleProperty property changed handler. /// </summary> /// <param name="dependencyObject">AccordionItem that changed its ExpandableContentControlStyle.</param> /// <param name="e">Event arguments.</param> private static void OnExpandableContentControlStylePropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { AccordionItem source = (AccordionItem)dependencyObject; source.OnExpandableContentControlStyleChanged(e.OldValue as Style, e.NewValue as Style); }