Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Framework / System / Windows / Media / Animation / BeginStoryboard.cs / 1 / BeginStoryboard.cs
/****************************************************************************\
*
* File: BeginStoryboard.cs
*
* This object includes a Storyboard reference. When triggered, the Storyboard
* is started.
*
* Copyright (C) by Microsoft Corporation. All rights reserved.
*
\***************************************************************************/
using System.ComponentModel; // DefaultValueAttribute
using System.Diagnostics; // Debug.Assert
using System.Windows; // SR.Get
using System.Windows.Documents; // TableTemplate
using System.Windows.Markup; // IAddChild
namespace System.Windows.Media.Animation
{
///
/// BeginStoryboard will call begin on its Storyboard reference when
/// it is triggered.
///
[RuntimeNameProperty("Name")] // Enables INameScope.FindName to find BeginStoryboard objects.
[ContentProperty("Storyboard")] // Enables child without explicit tag.
public sealed class BeginStoryboard : TriggerAction
{
///
/// Creates an instance of the BeginStoryboard object.
///
public BeginStoryboard()
: base()
{
}
///
/// DependencyProperty to back the Storyboard property
///
public static readonly DependencyProperty StoryboardProperty =
DependencyProperty.Register( "Storyboard", typeof(Storyboard), typeof(BeginStoryboard) );
///
/// The Storyboard object that this action is associated with. This
/// must be specified before Invoke is called.
///
[DefaultValue(null)]
public Storyboard Storyboard
{
get
{
return GetValue(StoryboardProperty) as Storyboard;
}
set
{
ThrowIfSealed();
SetValue( StoryboardProperty, value );
}
}
///
/// Specify the hand-off behavior to use when starting the animation
/// clocks in this storyboard
///
[DefaultValue(HandoffBehavior.SnapshotAndReplace)]
public HandoffBehavior HandoffBehavior
{
get
{
return _handoffBehavior;
}
set
{
ThrowIfSealed();
if(HandoffBehaviorEnum.IsDefined(value))
{
_handoffBehavior = value;
}
else
{
throw new ArgumentException(SR.Get(SRID.Storyboard_UnrecognizedHandoffBehavior));
}
}
}
///
/// The name to use for referencing this Storyboard. This named is used
/// by a control action such as pause and resume. Defaults to null, which
/// means this storyboard is not going to be interactively controlled.
///
// Null == no interactive control == "Fire and Forget"
[DefaultValue(null)]
public string Name
{
get
{
return _name;
}
set
{
ThrowIfSealed();
if(value != null && !System.Windows.Markup.NameValidationHelper.IsValidIdentifierName(value))
{
// Duplicate the error string thrown from DependencyObject.SetValueValidateParams
throw new ArgumentException(SR.Get(SRID.InvalidPropertyValue, value, "Name"));
}
// Null is OK - it's to remove whatever name was previously set.
_name = value;
}
}
private void ThrowIfSealed()
{
if (IsSealed)
{
throw new InvalidOperationException(SR.Get(SRID.CannotChangeAfterSealed, "BeginStoryboard"));
}
}
// Bug #1329664 workaround to make beta 2
// Remove thread affinity when sealed, but before doing that, snapshot the
// current Storyboard value and remove *its* thread affinity too.
internal override void Seal()
{
if( !IsSealed )
{
// Gets our Storyboard value. This value may have come from a
// ResourceReferenceExpression or might have been a deferred
// reference that has since been realized.
Storyboard snapshot = GetValue(StoryboardProperty) as Storyboard;
if( snapshot == null )
{
// This is the same error thrown by Begin if the Storyboard
// property couldn't be resolved at Begin time. Since we're
// not allowing changes after this point, lack of resolution
// here means the same thing.
throw new InvalidOperationException(SR.Get(SRID.Storyboard_StoryboardReferenceRequired));
}
// We're planning to break our thread affinity - we also need to
// make sure the Storyboard can also be used accross threads.
if(!snapshot.CanFreeze)
{
throw new InvalidOperationException(SR.Get(SRID.Storyboard_UnableToFreeze));
}
if(!snapshot.IsFrozen)
{
snapshot.Freeze();
}
// Promote that snapshot into a local value. This is a no-op if it
// was a deferred reference or local Storyboard, but if it came from a
// ResourceReferenceExpression it will replace the Expression object
// with a snapshot of its current value.
Storyboard = snapshot;
}
else
{
; // base.Seal() will throw exception for us if already sealed.
}
base.Seal();
// Now we can break our thread affinity
DetachFromDispatcher();
}
///
/// Called when it's time to execute this storyboard action
///
internal sealed override void Invoke( FrameworkElement fe, FrameworkContentElement fce, Style targetStyle, FrameworkTemplate frameworkTemplate, Int64 layer )
{
Debug.Assert( fe != null || fce != null, "Caller of internal function failed to verify that we have a FE or FCE - we have neither." );
INameScope nameScope = null;
if( targetStyle != null )
{
nameScope = targetStyle;
}
else
{
Debug.Assert( frameworkTemplate != null );
nameScope = frameworkTemplate;
}
Begin( (fe != null ) ? (DependencyObject)fe : (DependencyObject)fce, nameScope, layer );
}
internal sealed override void Invoke( FrameworkElement fe )
{
Debug.Assert( fe != null, "Invoke needs an object as starting point");
Begin( fe, null, Storyboard.Layers.ElementEventTrigger );
}
private void Begin( DependencyObject targetObject, INameScope nameScope, Int64 layer )
{
if( Storyboard == null )
{
throw new InvalidOperationException(SR.Get(SRID.Storyboard_StoryboardReferenceRequired));
}
if( Name != null )
{
Storyboard.BeginCommon(targetObject, nameScope, _handoffBehavior, true /* == is controllable */, layer );
}
else
{
Storyboard.BeginCommon(targetObject, nameScope, _handoffBehavior, false /* == not controllable */, layer );
}
}
private HandoffBehavior _handoffBehavior = HandoffBehavior.SnapshotAndReplace;
private string _name = null;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
/****************************************************************************\
*
* File: BeginStoryboard.cs
*
* This object includes a Storyboard reference. When triggered, the Storyboard
* is started.
*
* Copyright (C) by Microsoft Corporation. All rights reserved.
*
\***************************************************************************/
using System.ComponentModel; // DefaultValueAttribute
using System.Diagnostics; // Debug.Assert
using System.Windows; // SR.Get
using System.Windows.Documents; // TableTemplate
using System.Windows.Markup; // IAddChild
namespace System.Windows.Media.Animation
{
///
/// BeginStoryboard will call begin on its Storyboard reference when
/// it is triggered.
///
[RuntimeNameProperty("Name")] // Enables INameScope.FindName to find BeginStoryboard objects.
[ContentProperty("Storyboard")] // Enables child without explicit tag.
public sealed class BeginStoryboard : TriggerAction
{
///
/// Creates an instance of the BeginStoryboard object.
///
public BeginStoryboard()
: base()
{
}
///
/// DependencyProperty to back the Storyboard property
///
public static readonly DependencyProperty StoryboardProperty =
DependencyProperty.Register( "Storyboard", typeof(Storyboard), typeof(BeginStoryboard) );
///
/// The Storyboard object that this action is associated with. This
/// must be specified before Invoke is called.
///
[DefaultValue(null)]
public Storyboard Storyboard
{
get
{
return GetValue(StoryboardProperty) as Storyboard;
}
set
{
ThrowIfSealed();
SetValue( StoryboardProperty, value );
}
}
///
/// Specify the hand-off behavior to use when starting the animation
/// clocks in this storyboard
///
[DefaultValue(HandoffBehavior.SnapshotAndReplace)]
public HandoffBehavior HandoffBehavior
{
get
{
return _handoffBehavior;
}
set
{
ThrowIfSealed();
if(HandoffBehaviorEnum.IsDefined(value))
{
_handoffBehavior = value;
}
else
{
throw new ArgumentException(SR.Get(SRID.Storyboard_UnrecognizedHandoffBehavior));
}
}
}
///
/// The name to use for referencing this Storyboard. This named is used
/// by a control action such as pause and resume. Defaults to null, which
/// means this storyboard is not going to be interactively controlled.
///
// Null == no interactive control == "Fire and Forget"
[DefaultValue(null)]
public string Name
{
get
{
return _name;
}
set
{
ThrowIfSealed();
if(value != null && !System.Windows.Markup.NameValidationHelper.IsValidIdentifierName(value))
{
// Duplicate the error string thrown from DependencyObject.SetValueValidateParams
throw new ArgumentException(SR.Get(SRID.InvalidPropertyValue, value, "Name"));
}
// Null is OK - it's to remove whatever name was previously set.
_name = value;
}
}
private void ThrowIfSealed()
{
if (IsSealed)
{
throw new InvalidOperationException(SR.Get(SRID.CannotChangeAfterSealed, "BeginStoryboard"));
}
}
// Bug #1329664 workaround to make beta 2
// Remove thread affinity when sealed, but before doing that, snapshot the
// current Storyboard value and remove *its* thread affinity too.
internal override void Seal()
{
if( !IsSealed )
{
// Gets our Storyboard value. This value may have come from a
// ResourceReferenceExpression or might have been a deferred
// reference that has since been realized.
Storyboard snapshot = GetValue(StoryboardProperty) as Storyboard;
if( snapshot == null )
{
// This is the same error thrown by Begin if the Storyboard
// property couldn't be resolved at Begin time. Since we're
// not allowing changes after this point, lack of resolution
// here means the same thing.
throw new InvalidOperationException(SR.Get(SRID.Storyboard_StoryboardReferenceRequired));
}
// We're planning to break our thread affinity - we also need to
// make sure the Storyboard can also be used accross threads.
if(!snapshot.CanFreeze)
{
throw new InvalidOperationException(SR.Get(SRID.Storyboard_UnableToFreeze));
}
if(!snapshot.IsFrozen)
{
snapshot.Freeze();
}
// Promote that snapshot into a local value. This is a no-op if it
// was a deferred reference or local Storyboard, but if it came from a
// ResourceReferenceExpression it will replace the Expression object
// with a snapshot of its current value.
Storyboard = snapshot;
}
else
{
; // base.Seal() will throw exception for us if already sealed.
}
base.Seal();
// Now we can break our thread affinity
DetachFromDispatcher();
}
///
/// Called when it's time to execute this storyboard action
///
internal sealed override void Invoke( FrameworkElement fe, FrameworkContentElement fce, Style targetStyle, FrameworkTemplate frameworkTemplate, Int64 layer )
{
Debug.Assert( fe != null || fce != null, "Caller of internal function failed to verify that we have a FE or FCE - we have neither." );
INameScope nameScope = null;
if( targetStyle != null )
{
nameScope = targetStyle;
}
else
{
Debug.Assert( frameworkTemplate != null );
nameScope = frameworkTemplate;
}
Begin( (fe != null ) ? (DependencyObject)fe : (DependencyObject)fce, nameScope, layer );
}
internal sealed override void Invoke( FrameworkElement fe )
{
Debug.Assert( fe != null, "Invoke needs an object as starting point");
Begin( fe, null, Storyboard.Layers.ElementEventTrigger );
}
private void Begin( DependencyObject targetObject, INameScope nameScope, Int64 layer )
{
if( Storyboard == null )
{
throw new InvalidOperationException(SR.Get(SRID.Storyboard_StoryboardReferenceRequired));
}
if( Name != null )
{
Storyboard.BeginCommon(targetObject, nameScope, _handoffBehavior, true /* == is controllable */, layer );
}
else
{
Storyboard.BeginCommon(targetObject, nameScope, _handoffBehavior, false /* == not controllable */, layer );
}
}
private HandoffBehavior _handoffBehavior = HandoffBehavior.SnapshotAndReplace;
private string _name = null;
}
}
// 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
- SqlNotificationRequest.cs
- BrowsableAttribute.cs
- DataGridViewSelectedRowCollection.cs
- DictationGrammar.cs
- Expression.DebuggerProxy.cs
- CodeSnippetExpression.cs
- ConfigurationManagerHelperFactory.cs
- InfoCardListRequest.cs
- ScriptComponentDescriptor.cs
- WebPartConnectionsConnectVerb.cs
- HashMembershipCondition.cs
- MessageLogTraceRecord.cs
- DataServiceBehavior.cs
- milrender.cs
- SchemaImporterExtensionsSection.cs
- StyleBamlRecordReader.cs
- HasCopySemanticsAttribute.cs
- TextElement.cs
- HybridDictionary.cs
- FunctionDescription.cs
- EntityDataSourceState.cs
- DockEditor.cs
- DataGridPageChangedEventArgs.cs
- ProxyManager.cs
- OperatingSystem.cs
- NamespaceCollection.cs
- DynamicDataResources.Designer.cs
- SwitchElementsCollection.cs
- SaveFileDialog.cs
- InstalledFontCollection.cs
- CompositeScriptReferenceEventArgs.cs
- ContentPresenter.cs
- WsdlBuildProvider.cs
- AnchoredBlock.cs
- ConnectionsZone.cs
- SpeechUI.cs
- FormViewCommandEventArgs.cs
- PageVisual.cs
- ListenerElementsCollection.cs
- File.cs
- BindingSource.cs
- GeometryGroup.cs
- NetSectionGroup.cs
- CompiledQuery.cs
- ProcessInfo.cs
- EmptyEnumerator.cs
- AccessText.cs
- ProfileSettingsCollection.cs
- BinaryMessageFormatter.cs
- EventMap.cs
- TemplateNodeContextMenu.cs
- WebPartHelpVerb.cs
- DashStyle.cs
- WorkItem.cs
- XsltFunctions.cs
- BindingNavigator.cs
- SplitterCancelEvent.cs
- MD5CryptoServiceProvider.cs
- NullableLongMinMaxAggregationOperator.cs
- dbdatarecord.cs
- UnicastIPAddressInformationCollection.cs
- AutoCompleteStringCollection.cs
- WebPartEditorApplyVerb.cs
- DesignTimeVisibleAttribute.cs
- FlowNode.cs
- handlecollector.cs
- StoreUtilities.cs
- WaitForChangedResult.cs
- ListControl.cs
- XmlUnspecifiedAttribute.cs
- IDQuery.cs
- DataPagerFieldCollection.cs
- NavigationFailedEventArgs.cs
- EditorPartChrome.cs
- Function.cs
- TemplateKeyConverter.cs
- XmlDataSourceNodeDescriptor.cs
- WinOEToolBoxItem.cs
- HashMembershipCondition.cs
- ObjectQueryProvider.cs
- PackageRelationshipSelector.cs
- GenericIdentity.cs
- KeySpline.cs
- RecognizerStateChangedEventArgs.cs
- SubqueryTrackingVisitor.cs
- CollectionViewProxy.cs
- XNodeSchemaApplier.cs
- DataGridViewDataConnection.cs
- HTTPRemotingHandler.cs
- SequenceNumber.cs
- DbgCompiler.cs
- PeerNameResolver.cs
- KeyGestureValueSerializer.cs
- ArraySortHelper.cs
- ImageClickEventArgs.cs
- JsonEnumDataContract.cs
- mactripleDES.cs
- UnknownBitmapEncoder.cs
- OutputWindow.cs
- AppDomainUnloadedException.cs