Exemple #1
0
        /// <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)
        {
            var ctrl       = (AccordionItem)d;
            var 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();
                }
            }
        }