开发者

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

[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)
 开发者_C百科   End Get
    Set(ByVal value As Boolean)
        SetValue(value)
    End Set
End Property


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜