2010-02-18 43 views
0

我目前創建了下面的類。出於某種原因,儘管我無法訪問通過我的xaml樣式創建的屬性。訪問xaml中的類屬性

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

此時出現「Invalid PropertyDescriptor value」錯誤。

我該怎麼做才能使這個屬性可訪問?

編輯:我曾嘗試創建一個DependencyProperty爲好,因爲我讀過這可以解決我的問題,但它似乎沒有。

編輯2:我已經試過

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

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

,但似乎他們並不要麼暴露的財產。我還將房產標記爲<Bindable(True)>,但這似乎沒有做任何事情。

任何線索我做錯了什麼?

回答

0

我最終創建了一個單獨的彈出式樣式,並在課程代碼中設置了我的對象樣式並設置了彈出式對話框PlacementTarget = Me

1

依賴屬性應該確實解決您的問題。並且不要忘記命名空間,即<Setter Property="s:Ribbon.Dropdown">,但如果您指定了TargetType,則不必爲setter中的屬性指定類所有者。這意味着你可以寫<Setter Property="Dropdown">

PS:你也可能遇到另一個問題,通過樣式設置視覺效果。 Read more。但這是另一個故事...