Is it possible to have a Shared/Static Dependency Property?

Posted by Matt H. on Stack Overflow See other posts from Stack Overflow or by Matt H.
Published on 2010-05-25T01:45:20Z Indexed on 2010/05/25 1:51 UTC
Read the original article Hit count: 247

Filed under:
|
|
|

[using VB.NET, but I can easily read C# code in responses]

I have a class called QuestionClipboard with ALL shared methods/properties.

I previously had a QuesitonClipboard.doesClipboardHaveContent function that returned true/false if there was a Object on my 'clipboard'.

I'd prefer to implement a Dependency Property so I can allow this true/false value to participate in data binding.

The "GetValue(dp as DependencyProperty)" method requires an object instance, which would mean that my Property CAN'T be shared!

Here is what the code would look like in my perfect world... Of course, the word "Shared" before the property declaration renders this code useless.

Private Shared clipboardHasContentPropertyKey As DependencyPropertyKey = DependencyProperty.RegisterReadOnly("clipboardHasContent", GetType(Boolean), GetType(QuestionClipboard), _
                                                                        New PropertyMetadata(False, Nothing, New CoerceValueCallback(AddressOf coerceClipboardHasContent)))
Private Shared clipboardHasContentProperty As DependencyProperty = clipboardHasContentPropertyKey.DependencyProperty

Public SHARED Property clipboardHasContent As Boolean
    Get
        Return GetValue(clipboardHasContentProperty)
    End Get
    Set(ByVal value As Boolean)
        SetValue(value)
    End Set
End Property

© Stack Overflow or respective owner

Related posts about .NET

Related posts about wpf