c# - PointAnimation targeting custom UserControl property -


i attempting animate position of usercontrol have created. problem similar question asked on msdn, without answer sadly.

https://social.msdn.microsoft.com/forums/vstudio/en-us/11ce8aaa-1059-4fe5-8f4d-0fa7978e6ff2/using-pointanimation-to-move-a-control?forum=wpf

to summarize, have created point type dependency property named 'position' use specify usercontrol's place on ui, , animate userconrol new location.

my problem syntax 1 believe, unsure of right syntax target usercontrol property (in code-behind).

public class subcontainer : control  {   public static readonly dependencyproperty positionproperty;    static subcontainer()   {      defaultstylekeyproperty.overridemetadata(typeof(subcontainer),          new frameworkpropertymetadata(typeof(subcontainer)));       positionproperty = dependencyproperty.register(          "position",          typeof(point),          typeof(subcontainer),          new propertymetadata(new point(0, 0)));   }    public point position   {      { return (point)getvalue(positionproperty); }      set { setvalue(positionproperty, value); }   }  

and animation:

        public void boxtransition()     {         point destination = new point(70, 300);         subcontainer box = (maincontent.children[0] container).children[0] subcontainer;         pointanimation transition = new pointanimation();         timespan timespan = timespan.fromseconds(2);          this.registername("target", box.position);         transition.from = box.position;         transition.to = destination;         storyboard.settargetname(transition, "target");         storyboard.settargetproperty(transition, new propertypath(box.position));         storyboard btransition = new storyboard();         btransition.children.add(transition);         btransition.begin();      } 

i following error:

object 'system.windows.point' cannot used accessor parameter propertypath. accessor parameter must dependencyproperty, propertyinfo, or propertydescriptor.

any alternatives animate control appreciated!

wpf allows directly start animation of uielement property without storyboard.

you wouldn't need more code this:

var transition = new pointanimation {     = new point(70, 300),     duration = timespan.fromseconds(2) };  box.beginanimation(subcontainer.positionproperty, transition); 

note above not set from property of pointanimation. way animation start current value of position property.


as alternative position property may put subcontainer control in canvas

<canvas>     <local:subcontainer x:name="box" canvas.left="0" canvas.top="0" .../> </canvas> 

and animate canvas.left , canvas.top properties:

var duration = timespan.fromseconds(2); box.beginanimation(canvas.leftproperty,     new doubleanimation { = 70, duration = duration }); box.beginanimation(canvas.topproperty,     new doubleanimation { = 300, duration = duration }); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -