Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / VisualStateGroup.cs / 1458001 / VisualStateGroup.cs
// --------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// -------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Media.Animation;
namespace System.Windows
{
///
/// A group of mutually exclusive visual states.
///
[ContentProperty("States")]
[RuntimeNameProperty("Name")]
public class VisualStateGroup : DependencyObject
{
///
/// The Name of the VisualStateGroup.
///
public string Name
{
get;
set;
}
///
/// VisualStates in the group.
///
public IList States
{
get
{
if (_states == null)
{
_states = new FreezableCollection();
}
return _states;
}
}
///
/// Transitions between VisualStates in the group.
///
public IList Transitions
{
get
{
if (_transitions == null)
{
_transitions = new FreezableCollection();
}
return _transitions;
}
}
///
/// VisualState that is currently applied.
///
public VisualState CurrentState
{
get;
internal set;
}
internal VisualState GetState(string stateName)
{
for (int stateIndex = 0; stateIndex < States.Count; ++stateIndex)
{
VisualState state = (VisualState)States[stateIndex];
if (state.Name == stateName)
{
return state;
}
}
return null;
}
internal Collection CurrentStoryboards
{
get
{
if (_currentStoryboards == null)
{
_currentStoryboards = new Collection();
}
return _currentStoryboards;
}
}
internal void StartNewThenStopOld(FrameworkElement element, params Storyboard[] newStoryboards)
{
// Remove the old Storyboards. Remove is delayed until the next TimeManager tick, so the
// handoff to the new storyboard is unaffected.
for (int index = 0; index < CurrentStoryboards.Count; ++index)
{
if (CurrentStoryboards[index] == null)
{
continue;
}
CurrentStoryboards[index].Remove(element);
}
CurrentStoryboards.Clear();
// Start the new Storyboards
for (int index = 0; index < newStoryboards.Length; ++index)
{
if (newStoryboards[index] == null)
{
continue;
}
newStoryboards[index].Begin(element, HandoffBehavior.SnapshotAndReplace, true);
// Hold on to the running Storyboards
CurrentStoryboards.Add(newStoryboards[index]);
// Silverlight had an issue where initially, a checked CheckBox would not show the check mark
// until the second frame. They chose to do a Seek(0) at this point, which this line
// is supposed to mimic. It does not seem to be equivalent, though, and WPF ends up
// with some odd animation behavior. I haven't seen the CheckBox issue on WPF, so
// commenting this out for now.
// newStoryboards[index].SeekAlignedToLastTick(element, TimeSpan.Zero, TimeSeekOrigin.BeginTime);
}
}
internal void RaiseCurrentStateChanging(FrameworkElement stateGroupsRoot, VisualState oldState, VisualState newState, FrameworkElement control)
{
if (CurrentStateChanging != null)
{
CurrentStateChanging(stateGroupsRoot, new VisualStateChangedEventArgs(oldState, newState, control, stateGroupsRoot));
}
}
internal void RaiseCurrentStateChanged(FrameworkElement stateGroupsRoot, VisualState oldState, VisualState newState, FrameworkElement control)
{
if (CurrentStateChanged != null)
{
CurrentStateChanged(stateGroupsRoot, new VisualStateChangedEventArgs(oldState, newState, control, stateGroupsRoot));
}
}
///
/// Raised when transition begins
///
public event EventHandler CurrentStateChanged;
///
/// Raised when transition ends and new state storyboard begins.
///
public event EventHandler CurrentStateChanging;
private Collection _currentStoryboards;
private FreezableCollection _states;
private FreezableCollection _transitions;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
// --------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// -------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Media.Animation;
namespace System.Windows
{
///
/// A group of mutually exclusive visual states.
///
[ContentProperty("States")]
[RuntimeNameProperty("Name")]
public class VisualStateGroup : DependencyObject
{
///
/// The Name of the VisualStateGroup.
///
public string Name
{
get;
set;
}
///
/// VisualStates in the group.
///
public IList States
{
get
{
if (_states == null)
{
_states = new FreezableCollection();
}
return _states;
}
}
///
/// Transitions between VisualStates in the group.
///
public IList Transitions
{
get
{
if (_transitions == null)
{
_transitions = new FreezableCollection();
}
return _transitions;
}
}
///
/// VisualState that is currently applied.
///
public VisualState CurrentState
{
get;
internal set;
}
internal VisualState GetState(string stateName)
{
for (int stateIndex = 0; stateIndex < States.Count; ++stateIndex)
{
VisualState state = (VisualState)States[stateIndex];
if (state.Name == stateName)
{
return state;
}
}
return null;
}
internal Collection CurrentStoryboards
{
get
{
if (_currentStoryboards == null)
{
_currentStoryboards = new Collection();
}
return _currentStoryboards;
}
}
internal void StartNewThenStopOld(FrameworkElement element, params Storyboard[] newStoryboards)
{
// Remove the old Storyboards. Remove is delayed until the next TimeManager tick, so the
// handoff to the new storyboard is unaffected.
for (int index = 0; index < CurrentStoryboards.Count; ++index)
{
if (CurrentStoryboards[index] == null)
{
continue;
}
CurrentStoryboards[index].Remove(element);
}
CurrentStoryboards.Clear();
// Start the new Storyboards
for (int index = 0; index < newStoryboards.Length; ++index)
{
if (newStoryboards[index] == null)
{
continue;
}
newStoryboards[index].Begin(element, HandoffBehavior.SnapshotAndReplace, true);
// Hold on to the running Storyboards
CurrentStoryboards.Add(newStoryboards[index]);
// Silverlight had an issue where initially, a checked CheckBox would not show the check mark
// until the second frame. They chose to do a Seek(0) at this point, which this line
// is supposed to mimic. It does not seem to be equivalent, though, and WPF ends up
// with some odd animation behavior. I haven't seen the CheckBox issue on WPF, so
// commenting this out for now.
// newStoryboards[index].SeekAlignedToLastTick(element, TimeSpan.Zero, TimeSeekOrigin.BeginTime);
}
}
internal void RaiseCurrentStateChanging(FrameworkElement stateGroupsRoot, VisualState oldState, VisualState newState, FrameworkElement control)
{
if (CurrentStateChanging != null)
{
CurrentStateChanging(stateGroupsRoot, new VisualStateChangedEventArgs(oldState, newState, control, stateGroupsRoot));
}
}
internal void RaiseCurrentStateChanged(FrameworkElement stateGroupsRoot, VisualState oldState, VisualState newState, FrameworkElement control)
{
if (CurrentStateChanged != null)
{
CurrentStateChanged(stateGroupsRoot, new VisualStateChangedEventArgs(oldState, newState, control, stateGroupsRoot));
}
}
///
/// Raised when transition begins
///
public event EventHandler CurrentStateChanged;
///
/// Raised when transition ends and new state storyboard begins.
///
public event EventHandler CurrentStateChanging;
private Collection _currentStoryboards;
private FreezableCollection _states;
private FreezableCollection _transitions;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- UIElementHelper.cs
- NumberSubstitution.cs
- IntSecurity.cs
- TableAutomationPeer.cs
- Rotation3DAnimationUsingKeyFrames.cs
- GeneralTransform3DGroup.cs
- HtmlShimManager.cs
- EventSinkHelperWriter.cs
- ThreadExceptionDialog.cs
- DisplayMemberTemplateSelector.cs
- TimeStampChecker.cs
- ReceiveParametersContent.cs
- EndpointDispatcher.cs
- MimePart.cs
- EntityDataSourceValidationException.cs
- AutomationElementIdentifiers.cs
- ToolStripPanelRow.cs
- ProcessModelSection.cs
- OracleConnectionStringBuilder.cs
- KeyConstraint.cs
- DtcInterfaces.cs
- MaskedTextBox.cs
- ParentControlDesigner.cs
- HtmlTernaryTree.cs
- WindowsListViewGroupHelper.cs
- BamlRecordHelper.cs
- ErrorWebPart.cs
- ViewBase.cs
- relpropertyhelper.cs
- OracleFactory.cs
- WriterOutput.cs
- SByteConverter.cs
- InternalControlCollection.cs
- HttpDigestClientCredential.cs
- SchemaNamespaceManager.cs
- CompleteWizardStep.cs
- StringFormat.cs
- ComponentEditorPage.cs
- HttpWriter.cs
- EtwTrace.cs
- ImmutableObjectAttribute.cs
- ProtocolsConfigurationHandler.cs
- XPathExpr.cs
- EdmTypeAttribute.cs
- Clipboard.cs
- MtomMessageEncodingBindingElement.cs
- Scheduling.cs
- ParameterExpression.cs
- Roles.cs
- PartBasedPackageProperties.cs
- MasterPageBuildProvider.cs
- SByteConverter.cs
- PhysicalAddress.cs
- X509CertificateCollection.cs
- CombinedGeometry.cs
- ViewGenResults.cs
- WorkflowMessageEventArgs.cs
- PerformanceCounter.cs
- MouseEventArgs.cs
- DragDeltaEventArgs.cs
- StylusPointDescription.cs
- ApplicationContext.cs
- _AutoWebProxyScriptEngine.cs
- DataGridViewCellFormattingEventArgs.cs
- ReadOnlyDictionary.cs
- NavigationFailedEventArgs.cs
- XmlnsCache.cs
- RepeaterCommandEventArgs.cs
- dsa.cs
- ZipIOFileItemStream.cs
- AssemblyInfo.cs
- PersonalizationProvider.cs
- WebConvert.cs
- InstanceNotReadyException.cs
- UserPersonalizationStateInfo.cs
- XmlMembersMapping.cs
- ValidatedControlConverter.cs
- TreeNodeStyleCollectionEditor.cs
- ItemsChangedEventArgs.cs
- ContentPresenter.cs
- MobileResource.cs
- TypeDelegator.cs
- StorageEntitySetMapping.cs
- ListViewInsertedEventArgs.cs
- VisualStyleRenderer.cs
- ISO2022Encoding.cs
- LineServicesRun.cs
- XmlFormatExtensionPrefixAttribute.cs
- GridLength.cs
- VarRemapper.cs
- SafeFileMappingHandle.cs
- OperationAbortedException.cs
- EmulateRecognizeCompletedEventArgs.cs
- TypeInitializationException.cs
- ExpressionParser.cs
- SqlCacheDependency.cs
- SiteMap.cs
- SQLChars.cs
- TimelineGroup.cs
- TreeNodeBinding.cs