AdornerProvider.Activate Method
Called when adorners are requested for the first time by the designer.
Namespace: Microsoft.Windows.Design.Interaction
Assembly: Microsoft.Windows.Design.Interaction (in Microsoft.Windows.Design.Interaction.dll)
Syntax
'Declaration
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
)
Parameters
- item
Type: Microsoft.Windows.Design.Model.ModelItem
A ModelItem representing the adorned element.
Remarks
The adorner provider may use the adorned element item or view to initialize the adorners. If this context is not required, the adorner provider can create the adorners in the constructor without a need to overload the Activate method. This method is called before the adorners are parented to the designer UI.
An AdornerProvider instance may be activated and deactivated several times during its lifetime. Implement the Activate and Deactivate methods accordingly.
Examples
The following code example shows how to override the Activate method to create an AdornerPanel to host a Slider control, which is used at design-time to set the Background property of the adorned control. For more information, see Walkthrough: Creating a Design-time Adorner.
' 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 Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Reference
Microsoft.Windows.Design.Interaction Namespace