/// <summary> /// Removes the current Accordion from the collection of selected /// items. /// </summary> /// <remarks> /// This API supports the .NET Framework infrastructure and is not /// intended to be used directly from your code. /// </remarks> void ISelectionItemProvider.RemoveFromSelection() { AccordionItem owner = OwnerAccordionItem; Accordion parent = owner.ParentAccordion; if (parent == null) { throw new InvalidOperationException("System.Windows.Controls.Properties.Resources.Automation_OperationCannotBePerformed"); } parent.SelectedItems.Remove(owner); }
/// <summary> /// Expands the AccordionItem. /// </summary> /// <remarks> /// This API supports the .NET Framework infrastructure and is not /// intended to be used directly from your code. /// </remarks> void IExpandCollapseProvider.Expand() { if (!IsEnabled()) { throw new ElementNotEnabledException(); } AccordionItem owner = OwnerAccordionItem; if (owner.IsLocked) { throw new InvalidOperationException("System.Windows.Controls.Properties.Resources.Automation_OperationCannotBePerformed"); } owner.IsSelected = true; }
/// <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, "Properties.Resources.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, "Properties.Resources.Expander_OnExpandDirectionPropertyChanged_InvalidValue", newValue); throw new ArgumentException(message, "e"); } if (ctrl.ExpandSite != null) { // Jump to correct percentage after a direction change ctrl.ExpandSite.Percentage = ctrl.IsSelected ? 1 : 0; } ctrl.UpdateVisualState(true); }
/// <summary> /// Retrieves a UI Automation provider for each child element that is /// selected. /// </summary> /// <returns>An array of UI Automation providers.</returns> /// <remarks> /// This API supports the .NET Framework infrastructure and is not /// intended to be used directly from your code. /// </remarks> public IRawElementProviderSimple[] GetSelection() { Accordion owner = OwnerAccordion; List <IRawElementProviderSimple> selection = new List <IRawElementProviderSimple>(owner.SelectedIndices.Count); foreach (int index in owner.SelectedIndices) { AccordionItem item = owner.ItemContainerGenerator.ContainerFromIndex(index) as AccordionItem; if (item != null) { AutomationPeer peer = FromElement(item); if (peer != null) { selection.Add(ProviderFromPeer(peer)); } } } return(selection.ToArray()); }
/// <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("Properties.Resources.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(); } } }
protected override IList <AutomationPeer> GetChildrenCore() { Accordion owner = OwnerAccordion; ItemCollection items = owner.Items; if (items.Count <= 0) { return(null); } List <AutomationPeer> peers = new List <AutomationPeer>(items.Count); for (int i = 0; i < items.Count; i++) { AccordionItem element = owner.ItemContainerGenerator.ContainerFromIndex(i) as AccordionItem; if (element != null) { peers.Add(FromElement(element) ?? CreatePeerForElement(element)); } } return(peers); }
/// <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("Properties.Resources.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.Percentage = 1; } else { // otherwise schedule the resize source.Schedule(AccordionAction.Resize); } } } }
/// <summary> /// Initializes a new instance of the AccordionAutomationPeer class. /// </summary> /// <param name="owner"> /// The Accordion that is associated with this /// AccordionAutomationPeer. /// </param> public AccordionItemAutomationPeer(AccordionItem owner) : base(owner) { }
/// <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> /// Starts the next action in the list, in a particular order. /// </summary> /// <remarks>An AccordionItem is should always signal that it is /// finished with an action.</remarks> private void StartNextAction() { if (_currentActioningItem != null) { return; } // First do collapses, then resizes and finally expands. AccordionItem next = _scheduledActions.FirstOrDefault(item => item.ScheduledAction == AccordionAction.Collapse); if (next == null) { next = _scheduledActions.FirstOrDefault(item => item.ScheduledAction == AccordionAction.Resize); } if (next == null) { next = _scheduledActions.FirstOrDefault(item => item.ScheduledAction == AccordionAction.Expand); } if (next != null) { _currentActioningItem = next; _scheduledActions.Remove(next); next.StartAction(); } }
/// <summary> /// Signals the finish of an action by an item. /// </summary> /// <param name="item">The AccordionItem that finishes an action.</param> /// <remarks>An AccordionItem should always signal a finish, for this call /// will start the next scheduled action.</remarks> internal virtual void OnActionFinish(AccordionItem item) { if (SelectionSequence == SelectionSequence.CollapseBeforeExpand) { lock (this) { if (!_currentActioningItem.Equals(item)) { throw new InvalidOperationException("Properties.Resources.Accordion_OnActionFinish_InvalidFinish"); } _currentActioningItem = null; StartNextAction(); } } }
/// <summary> /// Allows an AccordionItem to signal the need for a visual action /// (resize, collapse, expand). /// </summary> /// <param name="item">The AccordionItem that signals for a schedule.</param> /// <param name="action">The action it is scheduling for.</param> /// <returns>True if the item is allowed to proceed without scheduling, /// false if the item needs to wait for a signal to execute the action.</returns> internal async virtual Task<bool> ScheduleAction(AccordionItem item, AccordionAction action) { if (SelectionSequence == SelectionSequence.CollapseBeforeExpand) { lock (this) { if (!_scheduledActions.Contains(item)) { _scheduledActions.Add(item); } } if (_currentActioningItem == null) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, StartNextAction); } return false; } else { return true; } }
internal void OnHeaderSizeChange(AccordionItem item) { LayoutChildren(); }
/// <summary> /// Called when an AccordionItem selected. /// </summary> /// <param name="accordionItem">The accordion item that was selected.</param> internal void OnAccordionItemSelected(AccordionItem accordionItem) { SelectItem(ItemContainerGenerator.IndexFromContainer(accordionItem)); }