AdornerProvider.Activate 메서드
디자이너에서 표시기를 처음 요청할 때 호출됩니다.
네임스페이스: Microsoft.Windows.Design.Interaction
어셈블리: Microsoft.Windows.Design.Interaction(Microsoft.Windows.Design.Interaction.dll)
구문
‘선언
Protected Overridable Sub Activate ( _
item As ModelItem _
)
protected virtual void Activate(
ModelItem item
)
protected:
virtual void Activate(
ModelItem^ item
)
abstract Activate :
item:ModelItem -> unit
override Activate :
item:ModelItem -> unit
protected function Activate(
item : ModelItem
)
매개 변수
- item
형식: Microsoft.Windows.Design.Model.ModelItem
표시된 요소를 나타내는 ModelItem입니다.
설명
표시기 공급자는 표시된 요소 항목 또는 뷰를 사용하여 표시기를 초기화할 수 있습니다. 이러한 컨텍스트가 필요하지 않은 경우 표시기 공급자는 Activate 메서드를 오버로드하지 않고 생성자에서 표시기를 만들 수 있습니다. 이 메서드는 표시기가 디자이너 UI의 부모로 지정되기 전에 호출됩니다.
AdornerProvider 인스턴스를 해당 수명 동안 여러 번 활성화하고 비활성화해야 할 수도 있습니다. 이를 고려하여 Activate 및 Deactivate 메서드를 구현합니다.
예제
다음 코드 예제에서는 Activate 메서드를 재정의하여 디자인 타임에 표시된 컨트롤의 Background 속성을 설정하는 데 사용되는 AdornerPanel을 만들어 Slider 컨트롤을 호스팅하는 방법을 보여 줍니다. 자세한 내용은 연습: 디자인 타임 표시기 만들기을 참조하십시오.
' The following method is called when the adorner is activated.
' It creates the adorner control, sets up the adorner panel,
' and attaches a ModelItem to the adorned control.
Protected Overrides Sub Activate(ByVal item As ModelItem)
' Save the ModelItem and hook into when it changes.
' This enables updating the slider position when
' a new Background value is set.
adornedControlModel = item
AddHandler adornedControlModel.PropertyChanged, AddressOf AdornedControlModel_PropertyChanged
' Setup the slider's min and max values.
opacitySlider.Minimum = 0
opacitySlider.Maximum = 1
' Setup the adorner panel.
' All adorners are placed in an AdornerPanel
' for sizing and layout support.
Dim myPanel = Me.Panel
' The slider extends the full width of the control it adorns.
AdornerPanel.SetAdornerHorizontalAlignment( _
opacitySlider, _
AdornerHorizontalAlignment.Stretch)
' Position the adorner above the control it adorns.
AdornerPanel.SetAdornerVerticalAlignment( _
opacitySlider, _
AdornerVerticalAlignment.OutsideTop)
' Position the adorner 5 pixels above the control.
AdornerPanel.SetAdornerMargin( _
opacitySlider, _
New Thickness(0, 0, 0, 5))
' Initialize the slider when it is loaded.
AddHandler opacitySlider.Loaded, AddressOf slider_Loaded
' Handle the value changes of the slider control.
AddHandler opacitySlider.ValueChanged, AddressOf slider_ValueChanged
AddHandler opacitySlider.PreviewMouseLeftButtonUp, _
AddressOf slider_MouseLeftButtonUp
AddHandler opacitySlider.PreviewMouseLeftButtonDown, _
AddressOf slider_MouseLeftButtonDown
MyBase.Activate(item)
End Sub
' The Panel utility property demand-creates the
' adorner panel and adds it to the provider's
' Adorners collection.
Public ReadOnly Property Panel() As AdornerPanel
Get
If Me.opacitySliderAdornerPanel Is Nothing Then
Me.opacitySliderAdornerPanel = New AdornerPanel()
' Add the adorner to the adorner panel.
Me.opacitySliderAdornerPanel.Children.Add(opacitySlider)
' Add the panel to the Adorners collection.
Adorners.Add(opacitySliderAdornerPanel)
End If
Return Me.opacitySliderAdornerPanel
End Get
End Property
// The following method is called when the adorner is activated.
// It creates the adorner control, sets up the adorner panel,
// and attaches a ModelItem to the adorned control.
protected override void Activate(ModelItem item)
{
// Save the ModelItem and hook into when it changes.
// This enables updating the slider position when
// a new Background value is set.
adornedControlModel = item;
adornedControlModel.PropertyChanged +=
new System.ComponentModel.PropertyChangedEventHandler(
AdornedControlModel_PropertyChanged);
// Setup the slider's min and max values.
opacitySlider.Minimum = 0;
opacitySlider.Maximum = 1;
// Setup the adorner panel.
// All adorners are placed in an AdornerPanel
// for sizing and layout support.
AdornerPanel myPanel = this.Panel;
// The slider extends the full width of the control it adorns.
AdornerPanel.SetAdornerHorizontalAlignment(
opacitySlider,
AdornerHorizontalAlignment.Stretch);
// Position the adorner above the control it adorns.
AdornerPanel.SetAdornerVerticalAlignment(
opacitySlider,
AdornerVerticalAlignment.OutsideTop);
// Position the adorner 5 pixels above the control.
AdornerPanel.SetAdornerMargin(
opacitySlider,
new Thickness(0, 0, 0, 5));
// Initialize the slider when it is loaded.
opacitySlider.Loaded += new RoutedEventHandler(slider_Loaded);
// Handle the value changes of the slider control.
opacitySlider.ValueChanged +=
new RoutedPropertyChangedEventHandler<double>(
slider_ValueChanged);
opacitySlider.PreviewMouseLeftButtonUp +=
new System.Windows.Input.MouseButtonEventHandler(
slider_MouseLeftButtonUp);
opacitySlider.PreviewMouseLeftButtonDown +=
new System.Windows.Input.MouseButtonEventHandler(
slider_MouseLeftButtonDown);
base.Activate(item);
}
// The Panel utility property demand-creates the
// adorner panel and adds it to the provider's
// Adorners collection.
public AdornerPanel Panel
{
get
{
if (this.opacitySliderAdornerPanel == null)
{
opacitySliderAdornerPanel = new AdornerPanel();
opacitySliderAdornerPanel.Children.Add(opacitySlider);
// Add the panel to the Adorners collection.
Adorners.Add(opacitySliderAdornerPanel);
}
return this.opacitySliderAdornerPanel;
}
}
.NET Framework 보안
- 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.
참고 항목
참조
Microsoft.Windows.Design.Interaction 네임스페이스