[英]How can i create a Point Object in XAML?
there is a Line control which we can define like this: 有一个Line控件,我们可以这样定义:
<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? 整个要点是,我可以避免调用任何人有任何想法的Canvas.Top和Canvas.Left方法?
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. 如果XML命名空间
my
引用的命名空间中存在Point
类,并且它具有可兼容类型的名为X
, Y
和Fill
的可设置属性,那么在XAML中实例化对象就像您的示例一样简单。
Of course you may need to convert from the string "Red"
to a Brush
, but that's easy. 当然,您可能需要将字符串
"Red"
转换为Brush
,但这很容易。
The more interesting question is how exactly do you want to use that object ? 更为有趣的问题是您到底想如何使用该对象 ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.