简体   繁体   中英

How can i create a Point Object in XAML?

there is a Line control which we can define like this:

<Line X1="10" Y1="30" X2="100" Y2="100" Stroke="Red" />

I'd like to create a point object of which i could define like this

<my:Point X="12" Y="44" Fill="Red" />

the whole point of this is that i could avoid calling Canvas.Top and Canvas.Left methods anyone have any ideas?

If there is a Point class in the namespace referred to by the XML namespace my , and it has settable properties named X , Y and Fill of a compatible type, then instantiating an object in XAML is as simple as your example.

Of course you may need to convert from the string "Red" to a Brush , but that's easy.

The more interesting question is how exactly do you want to use that object ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM