从 AdornerLayout 或 Adorner 或装饰控件访问 AdornerPanel?
我正在尝试添加一个简单的文本块作为控件的装饰。但我希望它位于我装饰的控件上方。
这是装饰创建(问题不依赖于这段代码):
public void AddLabelDecoration()
{
AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);
TextBlock textBlockMarkTooltipContent = new TextBlock();
textBlockMarkTooltipContent.Text = "Test Label Adorner";
_labelAdornerMarkTooltipContentAdorner = new Adorner(this)
{
Child = textBlockMarkTooltipContent
};
adornerLayer.Add(_labelAdornerMarkTooltipContentAdorner);
}
我无法实现的是将装饰定位在装饰控件之上。我想使用此 MSDN 代码示例,它利用 AdornerPanel 来进行定位...
但是我还没有弄清楚如何访问 AdornerPanel 对象以便应用此 MSDN 代码示例...都不是我的装饰控件,来自 AdornedLayout 或 Adorner...
我承认我不清楚 AdornerPanel 和 AdornerLayout 之间的 WPF 类层次结构。
任何帮助表示赞赏。
I am trying to add an simple Textblock as adorment to a control. But I want it to be positionned just above my adorned control.
This is the decoration creation ( the problem doesnt rely in this code):
public void AddLabelDecoration()
{
AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);
TextBlock textBlockMarkTooltipContent = new TextBlock();
textBlockMarkTooltipContent.Text = "Test Label Adorner";
_labelAdornerMarkTooltipContentAdorner = new Adorner(this)
{
Child = textBlockMarkTooltipContent
};
adornerLayer.Add(_labelAdornerMarkTooltipContentAdorner);
}
What I cannot achieve to do, is the positionning of the Decoration, above the adorned control. I would like to use this MSDN code sample, which makes use of AdornerPanel so as to do the positionning...
However I have not figured out how to access to an AdornerPanel object so as to apply this MSDN code sample... neither from my adorned control, from the AdornedLayout, or the Adorner...
I admit I don't clear understand the WPF class hierarchy between AdornerPanel and AdornerLayout.
Any help appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了移动你的装饰器,你必须重写 ArrangeOverride 方法并在那里调整新的装饰器位置。
下面是一个带有简单 FrameworkElementAdorner 的示例。
用法:
In order to move your Adorner you have to override the ArrangeOverride method and adjust a new adorner position there.
Here's an example with a simple FrameworkElementAdorner.
Usage: