views:

71

answers:

2

[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
A: 

See 1st comment for answer

Matt H.
Can you mark this as answered (even though this isn't the answer)? At least then it will be identified as answered.
Alastair Pitts
A: 

Making my comment an answer.

Use a singleton object instead of all static/shared properties. Here's an example in C# (VB.NET isn't too far off) and just have the singleton class inherit from DependencyObject.

Adam Sills