c# - Why a custom dependency property is not animated by a DoubleAnimation? -
i have following wpf window:
<window x:class="animationtest.mainwindow" x:name="main" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" height="350" width="525" > <window.resources> <storyboard repeatbehavior="forever" x:key="animationstoryboard" targetname="main" targetproperty="currentoffset" > <doubleanimation from="0" to="100" duration="0:0:5" speedratio=".8" autoreverse="true" /> </storyboard> </window.resources> <grid> </grid> </window> with following code behind:
using system.windows; using system.windows.media.animation; namespace animationtest { public partial class mainwindow : window { public static dependencyproperty currentoffsetproperty = dependencyproperty.register("currentoffset", typeof(double), typeof(mainwindow), new frameworkpropertymetadata(oncurrentoffsetpropertychanged)); private static void oncurrentoffsetpropertychanged(dependencyobject d, dependencypropertychangedeventargs e) { mainwindow control = (mainwindow)d; } public double currentoffset { { return (double)base.getvalue(mainwindow.currentoffsetproperty); } set { messagebox.show("hit"); base.setvalue(mainwindow.currentoffsetproperty, value); } } public mainwindow() { initializecomponent(); ((storyboard)base.findresource("animationstoryboard")).begin(this); } } } i expected have currentoffset property continuosly called nothing happens. it's animation won't start. can point me wrong?
thanks in advance.
adding previous comment , @clemens
just tried code myself , works fine. you'll ofc have "do work" in propertychanged handler dp works expected.
i modified storyboard not repeat test dp value such as:
<storyboard x:key="animationstoryboard" targetproperty="currentoffset" targetname="main"> <doubleanimation duration="0:0:5" from="0" speedratio=".8" to="100" /> </storyboard> and code-behind:
public mainwindow() { initializecomponent(); var sb = ((storyboard)base.findresource("animationstoryboard")); sb.completed += (sender, args) => messagebox.show(currentoffset.tostring()); sb.begin(); } messagebox invoked value of 99.8888... looks it's pretty working fine.
Comments
Post a Comment