internal void SetState(State newState, bool useTransitions) { _state = newState; switch (_state) { case State.Normal: VisualStateManager.GoToState(this, NormalStateName, useTransitions); break; case State.Expanded: VisualStateManager.GoToState(this, ExpandedStateName, useTransitions); break; case State.Selected: VisualStateManager.GoToState(this, SelectedStateName, useTransitions); break; } }
private LoopingSelectorItem CreateAndAddItem(Panel parent, object content) { bool reuse = _temporaryItemsPool != null && _temporaryItemsPool.Count > 0; LoopingSelectorItem wrapper = reuse ? _temporaryItemsPool.Dequeue() : new LoopingSelectorItem(); if (!reuse) { wrapper.ContentTemplate = this.ItemTemplate; wrapper.Width = ItemSize.Width; wrapper.Height = ItemSize.Height; wrapper.Padding = ItemMargin; wrapper.Click += OnWrapperClick; } wrapper.DataContext = wrapper.Content = content; parent.Children.Add(wrapper); // Need to do this before calling ApplyTemplate if (!reuse) { wrapper.ApplyTemplate(); wrapper.SetState(LoopingSelectorItem.State.Normal, false); } // Item should be visible if this control is expanded. if (IsExpanded) { // Uses transitions only when going from normal to expanded state. wrapper.SetState(LoopingSelectorItem.State.Expanded, !_actualIsExpanded); } return(wrapper); }