/// <summary> /// ExpandableContentControlStyleProperty property changed handler. /// </summary> /// <param name="d">AccordionItem that changed its ExpandableContentControlStyle.</param> /// <param name="e">Event arguments.</param> private static void OnExpandableContentControlStylePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AccordionItem source = (AccordionItem)d; source.OnExpandableContentControlStyleChanged(e.OldValue as Style, e.NewValue as Style); }
/// <summary> /// AccordionButtonStyleProperty property changed handler. /// </summary> /// <param name="d">AccordionItem that changed its AccordionButtonStyle.</param> /// <param name="e">Event arguments.</param> private static void OnAccordionButtonStylePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AccordionItem source = (AccordionItem)d; source.OnAccordionButtonStyleChanged(e.OldValue as Style, e.NewValue as Style); }
/// <summary> /// ExpandDirectionProperty PropertyChangedCallback call back static /// function. /// This function validates the new value before calling virtual function /// OnExpandDirectionChanged. /// </summary> /// <param name="d"> /// 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 d, DependencyPropertyChangedEventArgs e) { AccordionItem ctrl = (AccordionItem)d; 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, "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, "Expander_OnExpandDirectionPropertyChanged_InvalidValue" + newValue); throw new ArgumentException(message, "e"); } if (ctrl.ExpandSite != null) { // Jump to correct percentage after a direction change #if SILVERLIGHT ctrl.ExpandSite.Percentage = ctrl.IsSelected ? 1 : 0; #else ctrl.ExpandSite.RecalculatePercentage(ctrl.IsSelected ? 1 : 0); #endif } ctrl.UpdateVisualState(true); }
/// <summary> /// SelectedProperty PropertyChangedCallback static function. /// </summary> /// <param name="d">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 d, DependencyPropertyChangedEventArgs e) { AccordionItem ctrl = (AccordionItem)d; 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( "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="d">AccordionItem that changed its ContentTargetSize.</param> /// <param name="e">Event arguments.</param> private static void OnContentTargetSizePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AccordionItem source = (AccordionItem)d; Size targetSize = (Size)e.NewValue; if (!source._allowedToWriteContentTargetSize) { // revert to old value source.ContentTargetSize = (Size)e.OldValue; throw new InvalidOperationException("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 #if SILVERLIGHT expandSite.Percentage = 1; #else expandSite.RecalculatePercentage(1); #endif } else { // otherwise schedule the resize source.Schedule(AccordionAction.Resize); } } } }
/// <summary> /// Constructor /// </summary> /// <param name="item">The <see cref="T:System.Windows.Controls.AccordionItem" /> to wrap.</param> public AccordionItemWrapperAutomationPeer(AccordionItem item) : base(item) { }