Windows Presentation Foundation Designer Extensibility for Visual Studio
DefaultInitializer Class

Used to configure a new object in the designer.

Namespace:  Microsoft.Windows.Design.Model
Assembly:  Microsoft.Windows.Design.Extensibility (in Microsoft.Windows.Design.Extensibility.dll)
Syntax

Visual Basic (Declaration)
Public MustInherit Class DefaultInitializer _
    Inherits FeatureProvider
Visual Basic (Usage)
Dim instance As DefaultInitializer
C#
public abstract class DefaultInitializer : FeatureProvider
Visual C++
public ref class DefaultInitializer abstract : public FeatureProvider
JScript
public abstract class DefaultInitializer extends FeatureProvider
Remarks

The DefaultInitializer extension is invoked when the user adds an object from the Toolbox to the design surface. Derive from the DefaultInitializer class to configure default initial values for your object. For example, you might add some default content to a button control or set a panel's width and height to a constant value, so that it does not collapse to zero size when it is added to the design surface. When created from the Toolbox, the element's property values appear in XAML view.

NoteNote:

Do not set default initial values in an element's constructor. The designer may not call your constructor, and in this case your default initial values are not set at design time. Instead, use the DefaultInitializer class or the ClearValue method to set default initial values.

Examples

The following code example shows how to override the InitializeDefaults method to set the default value for a Button control's Content property to "Button".

Visual Basic
Imports System
Imports Microsoft.Windows.Design.Model
Imports Microsoft.Windows.Design.Features

<Feature(GetType(ButtonDefaults))>  _
Public Class DemoButton
End Class

Class ButtonDefaults
    Inherits DefaultInitializer

    Public Overrides Sub InitializeDefaults(ByVal item As ModelItem) 
        item.Content.SetValue("Button")

    End Sub
End Class
C#
using System;

using Microsoft.Windows.Design.Model;
using Microsoft.Windows.Design.Features;

namespace DemoControlLibrary.VisualStudio.Design
{
    [Feature(typeof(ButtonDefaults))]
    public class DemoButton { }

    class ButtonDefaults : DefaultInitializer
    {
        public override void InitializeDefaults(ModelItem item)
        {
            item.Content.SetValue("Button");
        }
    }
}
Inheritance Hierarchy

System..::.Object
  Microsoft.Windows.Design.Features..::.FeatureProvider
    Microsoft.Windows.Design.Model..::.DefaultInitializer
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Reference

Other Resources

Tags :


Page view tracker