DrawingAttributes.PropertyDataChanged 이벤트

정의

속성 데이터가 StrokeCollection에서 추가되거나 제거될 때 발생합니다.

public:
 event System::Windows::Ink::PropertyDataChangedEventHandler ^ PropertyDataChanged;
public event System.Windows.Ink.PropertyDataChangedEventHandler PropertyDataChanged;
member this.PropertyDataChanged : System.Windows.Ink.PropertyDataChangedEventHandler 
Public Custom Event PropertyDataChanged As PropertyDataChangedEventHandler 
Public Event PropertyDataChanged As PropertyDataChangedEventHandler 

이벤트 유형

예제

다음 예제는 3 차원 효과 그릴 수 있는 사용자 지정 스트로크의 일부입니다. 정의 하 고 호출 하는 사용자 지정 속성을 저장 하는 스트로크 Shadowed에 속하는 DrawingAttributes합니다. 경우는 Shadowed 속성 변경 내용을 PropertyDataChanged 이벤트 처리기 호출은 OnInvalidated 그릴 스트로크의 메서드.

class ShadowedStroke : Stroke
{

    // Be sure to pass in the DrawingAttributes when you create the stroke to
    // subscribe to the PropertyDataChaned event.
    public ShadowedStroke(StylusPointCollection stylusPoints, DrawingAttributes drawingAttributes)
        : base(stylusPoints, drawingAttributes)
    {
        this.DrawingAttributes.PropertyDataChanged += new PropertyDataChangedEventHandler(DrawingAttributes_PropertyDataChanged);
    }

    Guid shadow = new Guid("12345678-9012-3456-7890-123456789012");

    public bool Shadowed
    {
        // Return the value of the custom property, shadow.
        // If there is no custom property, return false.
        get
        {
            if (!this.DrawingAttributes.ContainsPropertyData(shadow))
            {
                return false;
            }

            object propertyData = this.DrawingAttributes.GetPropertyData(shadow);

            if (propertyData is bool)
            {
                return (bool)propertyData;
            }
            else
            {
                return false;
            }
        }

        // Set the value of the custom property.
        set
        {
            this.DrawingAttributes.AddPropertyData(shadow, value);
        }
    }

    void DrawingAttributes_PropertyDataChanged(object sender, PropertyDataChangedEventArgs e)
    {
         this.OnInvalidated(new EventArgs());
    }

    protected override void DrawCore(System.Windows.Media.DrawingContext context, DrawingAttributes overrides)
    {
        // create a drop shadow
        //
        if (this.Shadowed)
        {
            Geometry pathGeometry = this.GetGeometry(overrides).Clone();
            pathGeometry.Transform = new TranslateTransform(5, 0);
            try
            {
                context.PushOpacity(0.5);
                context.DrawGeometry(Brushes.DarkGray, null, pathGeometry);
            }
            finally
            {
                context.Pop();
            }
        }
        base.DrawCore(context, overrides);
    }
}

Class ShadowedStroke
    Inherits Stroke
    
    Private shadow As New Guid("12345678-9012-3456-7890-123456789012")

    Public Sub New(ByVal stylusPoints As StylusPointCollection, ByVal drawingAttributes As DrawingAttributes)
        MyBase.New(stylusPoints, drawingAttributes)

        AddHandler Me.DrawingAttributes.PropertyDataChanged, AddressOf DrawingAttributes_PropertyDataChanged

    End Sub

    Public Property Shadowed() As Boolean 

        ' Return the value of the custom property, shadow.
        ' If there is no custom property, return false.
        Get
            If Not Me.DrawingAttributes.ContainsPropertyData(shadow) Then
                Return False
            End If
            
            Dim propertyData As Object = Me.DrawingAttributes.GetPropertyData(shadow)
            
            If TypeOf propertyData Is Boolean Then
                Return CType(propertyData, Boolean)
            Else
                Return False
            End If
        End Get
        
        ' Set the value of the custom property.
        Set
            Me.DrawingAttributes.AddPropertyData(shadow, value)
        End Set 

    End Property
    
    
    Private Sub DrawingAttributes_PropertyDataChanged(ByVal sender As Object, ByVal e As PropertyDataChangedEventArgs)

        Me.OnInvalidated(New EventArgs())

    End Sub

    Protected Overrides Sub DrawCore(ByVal context As System.Windows.Media.DrawingContext, _
                                     ByVal overriddenAttributes As DrawingAttributes)
        ' create a drop shadow
        '
        If Me.Shadowed Then
            Dim pathGeometry As Geometry = Me.GetGeometry(overriddenAttributes).Clone()
            pathGeometry.Transform = New TranslateTransform(5, 0)
            Try
                context.PushOpacity(0.5)
                context.DrawGeometry(Brushes.DarkGray, Nothing, pathGeometry)
            Finally
                context.Pop()
            End Try
        End If
        MyBase.DrawCore(context, overriddenAttributes)

    End Sub
End Class

적용 대상