views:

85

answers:

2

I've currently created the class below. For some reason though I can't access the properties I've created through my xaml style.

Public Class Ribbon : Inherits Button
    Private mpopDropdown As Popup

    Public Property Dropdown() As Popup
        Get
            Return mpopDropdown
        End Get
        Set(ByVal value As Popup)
            mpopDropdown = value
        End Set
    End Property

    ...

End Class


<Style TargetType="{x:Type s:Ribbon}">
    <Setter Property="Ribbon.Dropdown">

At this point there is an "Invalid PropertyDescriptor value" error.

What can I do to make this property accessible?

EDIT: I have tried creating a DependencyProperty as well, as I've read this could solve my problem, but it didn't seem to.

EDIT 2: I've tried

Public Shared Readonly DropdownProperty as DependencyProperty = _
    DependencyProperty.Register("Dropdown",GetType(Popup),GetType(Ribbon), _
    New FrameworkPropertyMetadata(False))

and

Public Shared Readonly DropdownProperty as DependencyProperty = _
    DependencyProperty.Register("Dropdown",GetType(Popup),GetType(Ribbon), _
    New FrameworkPropertyMetadata(True))

but they don't seem to expose the property either. I've also tagged the property as <Bindable(True)> but that didn't seem to do anything.

Any clue what I'm doing wrong?

+1  A: 

Dependency properties should fix your problem indeed. And don't forget about namespace i.e. <Setter Property="s:Ribbon.Dropdown"> although you don't have to specify class owner for properties in setter, if you specified TargetType. That means you could write <Setter Property="Dropdown">

PS: You may also run into another problem with setting visuals through styles. Read more. But that's another story...

Anvaka
A: 

I ended up just creating a separate Popup style and setting the style of my object in the class's code and setting the Popup's PlacementTarget = Me.

smoore