将枚举值添加到 Silverlight 属性/属性
在
元素中,有 AlignmentX
和 AlignmentY
属性,其值为 Left/Center/Right 和 Top/Center/Bottom , 分别。
我想要做的是将我自己的值设置为 AlignmentX
中的值或另一个枚举,例如 AlignmentX="HalfCenter"
其中 HalfLeft
等于我自己的值(Center 和 Left 之间的中间值)。例如,如果我有这个:
<Rectangle Canvas.Left="0" Stroke="LimeGreen" StrokeThickness="16" Canvas.Top="0"
Width="400" Height="400" >
<Rectangle.Fill>
<ImageBrush ImageSource="newone.jpg"
Stretch="None" AlignmentX="HalfLeft" AlignmentY="Top" />
</Rectangle.Fill>
</Rectangle>
我不知道这是否是依赖属性、附加属性或其他属性(还不知道如何创建它们)。在帮助文件中,TileBrush.AlignmentXProperty
字段中显示:Public Shared ReadOnly AlignmentXProperty As DependencyProperty
。这里的“ReadOnly”一词是否意味着我无法将此属性设置为自定义属性?
如果这不能覆盖该属性,我该如何创建自己的属性?我认为这是一个附加属性,它可以被称为不同的东西,比如将 ImageBrush
设置到其父级内部的位置的 OffsetX
和 OffsetY
形状
。我对如何执行此操作的 SL 文档感到非常困惑(VB.NET 中几乎没有示例 - 但即使是 C# 的示例也不是那么具有启发性)。
如果可能的话,我该如何开始呢?
In the <ImageBrush/>
element, there are AlignmentX
and AlignmentY
attributes with values Left/Center/Right and Top/Center/Bottom, respectively.
What I'm wanting to do is set my own value in, for example, AlignmentX
either as a value or as another enumeration like AlignmentX="HalfCenter"
where HalfLeft
equals my own value (halfway between Center and Left). For example, if I have this:
<Rectangle Canvas.Left="0" Stroke="LimeGreen" StrokeThickness="16" Canvas.Top="0"
Width="400" Height="400" >
<Rectangle.Fill>
<ImageBrush ImageSource="newone.jpg"
Stretch="None" AlignmentX="HalfLeft" AlignmentY="Top" />
</Rectangle.Fill>
</Rectangle>
I don't know if this is a Dependency Property, Attached Property or otherwise (don't yet know how to create those). In the helpfile, it says in TileBrush.AlignmentXProperty
field: Public Shared ReadOnly AlignmentXProperty As DependencyProperty
. Does the ReadOnly word here mean that I can't set this property to a custom property?
If this can't be an override of that property, how can I create my own? I think this is an Attached Property and it could be called something different, like OffsetX
and OffsetY
that set an ImageBrush
to a location inside its parent Shape
. I'm getting very confused by the SL documentation on how I would do this though (almost no examples in VB.NET - but even the C# ones aren't all that revealing).
If it is possible, how would I get started on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了省去痛苦,只需使用值转换器,即使这样也会有点棘手,因为您必须应用渲染转换或其他东西来对枚举做出反应。
您也可以编写自己的面板,这可能是一个更好的主意。
您需要面对一些不同的问题,创建附加属性,验证枚举,让枚举在设置时执行您希望它执行的操作。
您还必须了解 MeasureOverride 和 ArrangeOverride
如果您无法控制自己, ... 看这里
Save yourself the pain and just use a value convertor and even that is going to be a little tricky, since you are going to have to apply a rendertransform or something to react to your enums.
You also could write your own panel which is probably a better idea.
You have a few different problems here to confront, creating the attached property, validating the enum, having the enum do what you want it to do when it is set.
Your also going to have to learn about MeasureOverride and ArrangeOverride
If you just can't help yourself ... Look Here