AdornerPlacementCollection 类
更新:2007 年 11 月
在 AdornerPanel 内实现装饰器的精确定位。
命名空间: Microsoft.Windows.Design.Interaction
程序集: Microsoft.Windows.Design.Interaction(在 Microsoft.Windows.Design.Interaction.dll 中)
语法
声明
Public Class AdornerPlacementCollection _
Inherits ObservableCollection(Of IAdornerPlacement)
用法
Dim instance As AdornerPlacementCollection
public class AdornerPlacementCollection : ObservableCollection<IAdornerPlacement>
public ref class AdornerPlacementCollection : public ObservableCollection<IAdornerPlacement^>
public class AdornerPlacementCollection extends ObservableCollection<IAdornerPlacement>
备注
使用 AdornerPlacementCollection 类可以相对于所装饰的控件指定 AdornerPanel 的位置、大小和缩放属性。
调用 PositionRelativeToAdornerHeight 和 PositionRelativeToAdornerWidth 方法可以相对于装饰器控件的高度和宽度来放置 AdornerPanel。
调用 SizeRelativeToAdornerDesiredWidth 和 SizeRelativeToContentHeight 方法可以相对于装饰器控件的大小来确定 AdornerPanel 的大小。
调用基于对应内容的方法可以相对于所装饰的内容来确定 AdornerPanel 的大小和位置。
对大小和位置方法的调用是累计的。下面的代码示例演示对 PositionRelativeToAdornerHeight 方法的两次调用,调用效果是将 AdornerPanel 放置在所装饰的控件上,y 轴偏移量等于装饰器的高度加上五个像素。
' Position the adorner above the control it adorns.
placement.PositionRelativeToAdornerHeight(-1.0, 0)
' Position the adorner up 5 pixels. This demonstrates
' that these placement calls are additive. These two calls
' are equivalent to the following single call:
' PositionRelativeToAdornerHeight(-1.0, -5).
placement.PositionRelativeToAdornerHeight(0, -5)
// Position the adorner above the control it adorns.
placement.PositionRelativeToAdornerHeight(-1.0, 0);
// Position the adorner up 5 pixels. This demonstrates
// that these placement calls are additive. These two calls
// are equivalent to the following single call:
// PositionRelativeToAdornerHeight(-1.0, -5).
placement.PositionRelativeToAdornerHeight(0, -5);
示例
下面的代码示例演示如何使用 AdornerPlacementCollection 来指定装饰器在装饰器面板中的位置。有关更多信息,请参见演练:创建设计时装饰器。
Dim placement As New AdornerPlacementCollection()
' The adorner's width is relative to the content.
' The slider extends the full width of the control it adorns.
placement.SizeRelativeToContentWidth(1.0, 0)
' The adorner's height is the same as the slider's.
placement.SizeRelativeToAdornerDesiredHeight(1.0, 0)
' Position the adorner above the control it adorns.
placement.PositionRelativeToAdornerHeight(-1.0, 0)
' Position the adorner up 5 pixels. This demonstrates
' that these placement calls are additive. These two calls
' are equivalent to the following single call:
' PositionRelativeToAdornerHeight(-1.0, -5).
placement.PositionRelativeToAdornerHeight(0, -5)
AdornerPanel.SetPlacements(opacitySlider, placement)
AdornerPlacementCollection placement = new AdornerPlacementCollection();
// The adorner's width is relative to the content.
// The slider extends the full width of the control it adorns.
placement.SizeRelativeToContentWidth(1.0, 0);
// The adorner's height is the same as the slider's.
placement.SizeRelativeToAdornerDesiredHeight(1.0, 0);
// Position the adorner above the control it adorns.
placement.PositionRelativeToAdornerHeight(-1.0, 0);
// Position the adorner up 5 pixels. This demonstrates
// that these placement calls are additive. These two calls
// are equivalent to the following single call:
// PositionRelativeToAdornerHeight(-1.0, -5).
placement.PositionRelativeToAdornerHeight(0, -5);
AdornerPanel.SetPlacements(opacitySlider, placement);
继承层次结构
System.Object
System.Collections.ObjectModel.Collection<IAdornerPlacement>
System.Collections.ObjectModel.ObservableCollection<IAdornerPlacement>
Microsoft.Windows.Design.Interaction.AdornerPlacementCollection
线程安全
此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。
另请参见
参考
Microsoft.Windows.Design.Interaction 命名空间
PrimarySelectionAdornerProvider