Search code examples
c#wpf

pass a point parameter to a user control


I have a user control that needs a Point. For example for location. <controls:MyUserControl Location="Point"/> I'm not using binding and Location is an object not a Point because It can be everthing.

I tried: <controls:MyUserControl Location="1,1"/> <controls:MyUserControl Location="1 1"/> and <controls:MyUserControl Location={1 1}/> none of them works. Is using converters are my only ways?


Solution

  • If Location would be of type Point, writing Location="1,1" or Location="1 1" would have worked, because Point already has a Type converter assigned.

    But as it is of type object, you will have to construct a point instance explicitely.

    This should work using Property Element Syntax:

    <controls:MyUserControl>
      <controls:MyUserControl.Location>
        <Point X="1" Y="1" />
      <controls:MyUserControl.Location>
    </controls:MyUserControl>