文档详情

WPF实现跳动的字符效果.docx

发布:2025-05-12约2.09千字共2页下载文档
文本预览下载声明

WPF实现跳动的字符效果

privatestring_textEffectName;

privateTranslateTransform_translateTransform=null;

privatestring_translateTransformName;

privateStoryboard_storyboard;

protectedoverridevoidOnAttached()

base.OnAttached();

this.AssociatedObject.Loaded+=AssociatedObject_Loaded;

this.AssociatedObject.Unloaded+=AssociatedObject_Unloaded;

this.AssociatedObject.IsVisibleChanged+=AssociatedObject_IsVisibleChanged;

BindingOperations.SetBinding(this,DanceCharEffectBehavior.InternalTextProperty,newBinding(Text){Source=this.AssociatedObject});

protectedoverridevoidOnDetaching()

base.OnDetaching();

this.AssociatedObject.Loaded-=AssociatedObject_Loaded;

this.AssociatedObject.Unloaded-=AssociatedObject_Unloaded;

this.AssociatedObject.IsVisibleChanged-=AssociatedObject_IsVisibleChanged;

this.ClearValue(DanceCharEffectBehavior.InternalTextProperty);

if(_storyboard!=null)

_storyboard.Remove(this.AssociatedObject);

_storyboard.Children.Clear();

if(_textEffect!=null)

this.AssociatedObject.TextEffects.Remove(_textEffect);

privatevoidAssociatedObject_IsVisibleChanged(objectsender,DependencyPropertyChangedEventArgse)

if((bool)e.NewValue==false)

if(_storyboard!=null)

_storyboard.Stop(this.AssociatedObject);

else

BeginEffect(this.AssociatedObject.Text);

privatevoidAssociatedObject_Loaded(objectsender,RoutedEventArgse)

if(_textEffect==null)

this.AssociatedObject.TextEffects.Add(_textEffect=newTextEffect()

PositionCount=1,

Transform=_translateTransform=newTranslateTransform(),

NameScope.SetNameScope(this.AssociatedObject,newNameScope());

this.AssociatedObject.RegisterName(_textEffectName=n+Guid.NewGuid().ToString(N),_textEffect);

this.AssociatedObject.RegisterName(_translateTransformName=n+Guid.NewGuid().ToString(N),_translateTransform);

if(IsEnabled)

BeginEffect(this.AssociatedObject.Text);

priv

显示全部
相似文档