This documentation is archived and is not being maintained.

NotifyParentPropertyAttribute Class

Indicates that the parent property is notified when the value of the property that this attribute is applied to is modified. This class cannot be inherited.

Namespace:  System.ComponentModel
Assembly:  System (in System.dll)

'Declaration
<AttributeUsageAttribute(AttributeTargets.Property)> _
Public NotInheritable Class NotifyParentPropertyAttribute _
	Inherits Attribute
'Usage
Dim instance As NotifyParentPropertyAttribute

Apply NotifyParentPropertyAttribute to a property if its parent property should receive notification of changes to the property's values. For example, in the Properties window, the DataGridView.RowTemplate property has nested properties such as Height and DefaultCellStyle. These nested properties are marked with NotifyParentPropertyAttribute(true) so they notify the parent property to update its value and display when the property values change.

For more information about using attributes, see Extending Metadata Using Attributes.

The following code example demonstrates how to use the NotifyParentPropertyAttribute and the ExpandableObjectConverter class to create an expandable property on a custom control.

Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Globalization
Imports System.Windows.Forms

Public Class DemoControl
    Inherits UserControl

    Private borderAppearanceValue As New BorderAppearance()
    Private components As System.ComponentModel.IContainer = Nothing 


    Public Sub New()
        InitializeComponent()

    End Sub 

    Protected Overrides Sub Dispose(ByVal disposing As Boolean)

        If disposing AndAlso (components IsNot Nothing) Then
            components.Dispose()
        End If 

        MyBase.Dispose(disposing)

    End Sub

    <Browsable(True), _
    EditorBrowsable(EditorBrowsableState.Always), _
    Category("Demo"), _
    DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
    Public Property Border() As BorderAppearance

        Get 
            Return Me.borderAppearanceValue
        End Get 

        Set(ByVal value As BorderAppearance)
            Me.borderAppearanceValue = value
        End Set 

    End Property 

    Private Sub InitializeComponent()
        components = New System.ComponentModel.Container()
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font

    End Sub 
End Class

<TypeConverter(GetType(BorderAppearanceConverter))>  _
Public Class BorderAppearance
    Private borderSizeValue As Integer = 1
    Private borderColorValue As Color = Color.Empty


    <Browsable(True), NotifyParentProperty(True), EditorBrowsable(EditorBrowsableState.Always), DefaultValue(1)>  _
    Public Property BorderSize() As Integer  
        Get 
            Return borderSizeValue
        End Get 
        Set 
            If value < 0 Then 
                Throw New ArgumentOutOfRangeException("BorderSize", value, "must be >= 0")
            End If 

            If borderSizeValue <> value Then
                borderSizeValue = value
            End If 
        End Set 
    End Property


    <Browsable(True), NotifyParentProperty(True), EditorBrowsable(EditorBrowsableState.Always), DefaultValue(GetType(Color), "")>  _
    Public Property BorderColor() As Color 
        Get 
            Return borderColorValue
        End Get 
        Set 
            If value.Equals(Color.Transparent) Then 
                Throw New NotSupportedException("Transparent colors are not supported.")
            End If 

            If borderColorValue <> value Then
                borderColorValue = value
            End If 
        End Set 
    End Property 
End Class 

Public Class BorderAppearanceConverter
    Inherits ExpandableObjectConverter

    ' This override prevents the PropertyGrid from  
    ' displaying the full type name in the value cell. 
    Public Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object, ByVal destinationType As Type) As Object

        If destinationType Is GetType(String) Then 
            Return "" 
        End If 

        Return MyBase.ConvertTo(context, culture, value, destinationType)

    End Function 
End Class

System.Object
  System.Attribute
    System.ComponentModel.NotifyParentPropertyAttribute

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: