简体   繁体   English

如何在XAML中创建Point Object?

[英]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类,并且它具有可兼容类型的名为XYFill的可设置属性,那么在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.

相关问题 如何在xaml中创建可重复使用的窗口内容? - How can I create re-usable window content in xaml? 如何使用XAML模板在silverlight上使用“ X”创建文本框? - How can I create a textbox with “X” on silverlight using XAML templates? 如何在不使用xaml的情况下自动在wpf中创建堆栈面板 - How can I create stackpanels in wpf automatically without using xaml 如何在 C# 代码而不是 XAML 中创建超链接 - How can I create a hyperlink in C# code instead of XAML 如何在XAML中使GridViewItem成为可拖动对象而不是DataTemplate? - How can I make a GridViewItem as a draggable object instead of a DataTemplate in XAML? 我可以创建一个接受XAML元素的DependencyProperty吗? - Can I create a DependencyProperty that accepts a XAML element? 我可以在 xaml 处分别绑定 Point 的 X 和 Y 属性吗? - Can I separately bind the X and Y properties of Point at xaml? 如何访问 WPF 代码隐藏中 ContentControl DataTemplate 中的 object,或者如何在 xaml 中设置 CefSharp DownloadHandler - How can I access an object that is in a ContentControl DataTemplate in WPF codebehind, or how do I set a CefSharp DownloadHandler in xaml 如何创建可以通过xaml创建的自定义Xamarin.Forms组件? - How can I create a custom Xamarin.Forms component that can be creating through xaml? 如何在XAML中创建“窗口”菜单? - How do I create a “Window” menu in XAML?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM