NotifyParentPropertyAttribute Sınıf
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Bu özniteliğin uygulandığı özelliğin değeri değiştirildiğinde üst özelliğin bildirildiğini gösterir. Bu sınıf devralınamaz.
public ref class NotifyParentPropertyAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Property)]
public sealed class NotifyParentPropertyAttribute : Attribute
public sealed class NotifyParentPropertyAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Property)>]
type NotifyParentPropertyAttribute = class
inherit Attribute
type NotifyParentPropertyAttribute = class
inherit Attribute
Public NotInheritable Class NotifyParentPropertyAttribute
Inherits Attribute
- Devralma
- Öznitelikler
Örnekler
Aşağıdaki kod örneği, özel denetimde genişletilebilir bir özellik oluşturmak için ve ExpandableObjectConverter sınıfının nasıl kullanılacağını NotifyParentPropertyAttribute gösterir.
using System;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;
namespace ExpandableObjectDemo;
public partial class DemoControl : UserControl
{
Container components;
public DemoControl() => InitializeComponent();
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
[Browsable(true)]
[EditorBrowsable(EditorBrowsableState.Always)]
[Category("Demo")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public BorderAppearance Border { get; set; } = new();
void InitializeComponent()
{
components = new Container();
AutoScaleMode = AutoScaleMode.Font;
}
}
[TypeConverter(typeof(BorderAppearanceConverter))]
public class BorderAppearance
{
int borderSizeValue = 1;
Color borderColorValue = Color.Empty;
[Browsable(true),
NotifyParentProperty(true),
EditorBrowsable(EditorBrowsableState.Always),
DefaultValue(1)]
public int BorderSize
{
get => borderSizeValue;
set
{
if (value < 0)
{
throw new ArgumentOutOfRangeException(
"BorderSize",
value,
"must be >= 0");
}
if (borderSizeValue != value)
{
borderSizeValue = value;
}
}
}
[Browsable(true)]
[NotifyParentProperty(true)]
[EditorBrowsable(EditorBrowsableState.Always)]
[DefaultValue(typeof(Color), "")]
public Color BorderColor
{
get => borderColorValue;
set
{
if (value.Equals(Color.Transparent))
{
throw new NotSupportedException("Transparent colors are not supported.");
}
if (borderColorValue != value)
{
borderColorValue = value;
}
}
}
}
public class BorderAppearanceConverter : ExpandableObjectConverter
{
// This override prevents the PropertyGrid from
// displaying the full type name in the value cell.
public override object ConvertTo(
ITypeDescriptorContext context,
CultureInfo culture,
object value,
Type destinationType) => destinationType == typeof(string)
? ""
: base.ConvertTo(
context,
culture,
value,
destinationType);
}
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
Açıklamalar
Üst özelliği, özelliğin değerlerinde yapılan değişikliklerin bildirimini alacaksa özelliğe uygulayın NotifyParentPropertyAttribute . Örneğin, Özellikler penceresinde özelliği ve DataGridView.RowTemplate gibi HeightDefaultCellStyleiç içe özelliklere sahiptir. Bu iç içe özellikler ile NotifyParentPropertyAttribute(true) işaretlendiğinden, üst özelliğe değerini güncelleştirmesini ve özellik değerleri değiştiğinde görüntülenmesini bildirir.
Öznitelikleri kullanma hakkında daha fazla bilgi için bkz . Öznitelikler.
Oluşturucular
| Name | Description |
|---|---|
| NotifyParentPropertyAttribute(Boolean) |
Üst özelliğe özelliğin değerinde yapılan NotifyParentPropertyAttribute değişiklikler bildirilip bildirilmediğini belirlemek için belirtilen değeri kullanarak sınıfının yeni bir örneğini başlatır. |
Alanlar
| Name | Description |
|---|---|
| Default |
Özelliğin üst özelliğine değerindeki değişiklikleri bildirmemesi gerektiğini varsayılan öznitelik durumunu gösterir. Bu alan salt okunurdur. |
| No |
Üst özelliğe, özelliğin değerinde yapılan değişiklikler bildirilmediğini gösterir. Bu alan salt okunurdur. |
| Yes |
Üst özelliğin, özelliğin değerindeki değişikliklerle ilgili bildirim alındığını gösterir. Bu alan salt okunurdur. |
Özellikler
| Name | Description |
|---|---|
| NotifyParent |
Üst özelliğin, özelliğin değerindeki değişikliklerle ilgili bildirim alınıp alınmayacağını belirten bir değer alır veya ayarlar. |
| TypeId |
Türetilmiş bir sınıfta uygulandığında, bu Attributeiçin benzersiz bir tanımlayıcı alır. (Devralındığı yer: Attribute) |
Yöntemler
| Name | Description |
|---|---|
| Equals(Object) |
Belirtilen nesnenin geçerli nesneyle aynı olup olmadığını belirten bir değer alır. |
| GetHashCode() |
Bu nesnenin karma kodunu alır. |
| GetType() |
Geçerli örneğin Type alır. (Devralındığı yer: Object) |
| IsDefaultAttribute() |
Özniteliğin geçerli değerinin öznitelik için varsayılan değer olup olmadığını belirten bir değer alır. |
| Match(Object) |
Türetilmiş bir sınıfta geçersiz kılındığında, bu örneğin belirtilen bir nesneye eşit olup olmadığını gösteren bir değer döndürür. (Devralındığı yer: Attribute) |
| MemberwiseClone() |
Geçerli Objectbasit bir kopyasını oluşturur. (Devralındığı yer: Object) |
| ToString() |
Geçerli nesneyi temsil eden bir dize döndürür. (Devralındığı yer: Object) |
Belirtik Arabirim Kullanımları
| Name | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Bir ad kümesini karşılık gelen bir dağıtma tanımlayıcısı kümesine eşler. (Devralındığı yer: Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Bir arabirimin tür bilgilerini almak için kullanılabilecek bir nesnenin tür bilgilerini alır. (Devralındığı yer: Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Bir nesnenin sağladığı tür bilgisi arabirimlerinin sayısını alır (0 ya da 1). (Devralındığı yer: Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Bir nesne tarafından kullanıma sunulan özelliklere ve yöntemlere erişim sağlar. (Devralındığı yer: Attribute) |