开发者

Accessing class properties in xaml

开发者 https://www.devze.com 2022-12-21 01:07 出处:网络
I\'ve currently created the class below.For some reason though I can\'t access the properties I\'ve created through my xaml style.

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.

开发者_JAVA技巧

Any clue what I'm doing wrong?


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...


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.

0

精彩评论

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

关注公众号